View Single Post
Old 09-21-2021, 10:21 PM   #100
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by KevinH View Post
So are you saying a possible plugin to "merge" stylesheets might be useful?
Perhaps...

I still think Style Mapping would be much more powerful.

I discussed that + "Consolidate Stylesheet" a few months back:

2021: "What Features or Tools does Sigil Still Need Yet?" (Post #163+)

InDesign has such a mapping function when doing EPUB Export.

For import, I also believe it also maps Word (DOCX) Styles -> InDesign Styles, so when you import those documents, you can quickly go through a table and say what gets assigned to what.

It speeds up the to-Print workflow dramatically.

Don't see why it couldn't speed up the to-clean-EPUB workflow as well.

Quote:
Originally Posted by KevinH View Post
Does it work on all selectors or only class selectors? How does it treat element selectors that differ across the sheets?
Unsure.

I rarely use anything beyond very basic classes in my ebooks, so I haven't done extensive testing into Calibre's innards to see exactly what it does with more complicated selectors.

During a Calibre EPUB->EPUB, I think it converts everything down to individual "calibre##" classes. For example:

Spoiler:

Code:
  <p>Testing</p>

  <blockquote>
    <p>This is an example</p>
    <p>of a larger blockquote.</p>
  </blockquote>

  <p>Testing</p>
Code:
p {
	margin-top: 0;
	margin-bottom: 0;
	text-align: justify;
	text-indent: 2em;
}

blockquote > p:first-child {
	background-color: red;
	margin-top: 1em;
	margin-bottom: 1em;
	text-indent: 0;
}

blockquote > p {
	background-color: yellow;
	padding-top: 1em;
	margin-bottom: 1em;
}


Click image for larger version

Name:	Basic.HTMLCSS.Example.png
Views:	143
Size:	3.1 KB
ID:	189347

Calibre EPUB->EPUB turned into:

Spoiler:

Code:
  <p class="calibre1">Testing</p>

  <blockquote class="calibre2">
    <p class="calibre3">This is an example</p>
    <p class="calibre4">of a larger blockquote.</p>
  </blockquote>

  <p class="calibre1">Testing</p>
Code:
.calibre {
    display: block;
    font-size: 1em;
    padding-left: 0;
    padding-right: 0;
    margin: 0 5pt
    }
.calibre1 {
    display: block;
    text-align: justify;
    text-indent: 2em;
    margin: 0
    }
.calibre2 {
    display: block;
    margin: 1em
    }
.calibre3 {
    background-color: yellow;
    display: block;
    padding-top: 1em;
    text-align: justify;
    text-indent: 0;
    margin: 1em 0
    }
.calibre4 {
    background-color: yellow;
    display: block;
    padding-top: 1em;
    text-align: justify;
    text-indent: 2em;
    margin: 0 0 1em
    }


(Side Note: The red background-color went poof. Suspecting it's a conversion bug.)

Quote:
Originally Posted by KevinH View Post
Hmm ... it would also need to:
Hmmm... similar to those Calibre checkboxes, it would be nice to completely strip/ignore certain properties.

Nice to have broad/easy-mode checkbox categories like "Colors" + "Margins" + "Floats".

But also a surgical/advanced-mode where you could specify attributes to strip:
  • letter-spacing
  • orphans
  • widows
  • text-transform
  • [...]

(Maybe a live list of all currently used properties within the CSS?)

So some InDesign cruft like this:

Spoiler:
Code:
p.Block-indent {
	color:#000000;
	font-family:"Minion Pro Medium", sans-serif;
	font-size:0.917em;
	font-style:normal;
	font-variant:normal;
	font-weight:normal;
	line-height:1.182;
	margin-bottom:5px;
	margin-left:36px;
	margin-right:36px;
	margin-top:5px;
	orphans:2;
	page-break-after:auto;
	page-break-before:auto;
	text-align:justify;
	text-decoration:none;
	text-indent:0;
	text-transform:none;
	widows:2;
}
Code:
p.Body-text {
	color:#000000;
	font-family:"Minion Pro Medium", sans-serif;
	font-size:0.917em;
	font-style:normal;
	font-variant:normal;
	font-weight:normal;
	line-height:1.2;
	margin-bottom:0;
	margin-left:0;
	margin-right:0;
	margin-top:1px;
	orphans:2;
	page-break-after:auto;
	page-break-before:auto;
	text-align:justify;
	text-decoration:none;
	text-indent:18px;
	text-transform:none;
	widows:2;
}


* * *

If you check 3... Remove:
  • Margins
  • line-height
  • text-indent

Those classes would now be considered equivalent.

So consolidate .Body-text -> Block-indent in CSS:

Spoiler:
Code:
p.Block-indent {
	color:#000000;
	font-family:"Minion Pro Medium", sans-serif;
	font-size:0.917em;
	font-style:normal;
	font-variant:normal;
	font-weight:normal;
	orphans:2;
	page-break-after:auto;
	page-break-before:auto;
	text-align:justify;
	text-decoration:none;
	text-transform:none;
	widows:2;
}


+ go through and update any HTML:

<p class="Block-indent"> -> <p class="Body-text">

* * *

If you say... Remove:
  • Margins
  • line-height

they'd be extremely close, but at least you'll strip/remove some trash:

Spoiler:
Code:
p.Block-indent {
	color:#000000;
	font-family:"Minion Pro Medium", sans-serif;
	font-size:0.917em;
	font-style:normal;
	font-variant:normal;
	font-weight:normal;
	orphans:2;
	page-break-after:auto;
	page-break-before:auto;
	text-align:justify;
	text-decoration:none;
	text-indent:0;
	text-transform:none;
	widows:2;
}

p.Body-text {
	color:#000000;
	font-family:"Minion Pro Medium", sans-serif;
	font-size:0.917em;
	font-style:normal;
	font-variant:normal;
	font-weight:normal;
	orphans:2;
	page-break-after:auto;
	page-break-before:auto;
	text-align:justify;
	text-decoration:none;
	text-indent:18px;
	text-transform:none;
	widows:2;
}


Update CSS, but do not update the HTML.

* * *

Would be Helpful: After this stage, if you had a "Style Mapper", you'd be able to select these 2 classes, then see their CSS compared side-by-side, highlighting the diffs.

Then you'd be able to:
  • Edit
    • Remove the "text-indent:18px;" line
    • Sigil updates the CSS.
      • (Optionally checks again to see if there's any matching classes that it can consolidate into now.)
  • Merge Left/Right
    • Be able to say:
      • Block-indent -> Body-text
      • OR Block-indent <- Body-text
    • Sigil updates CSS + HTML.
  • Rename
    • Block-indent now called "normal"
    • Sigil updates CSS + HTML:
      • p.Block-indent -> p.normal
      • <p class="Block-indent"> -> <p class="normal">

* * *

Side Note: Like I mentioned, I only ran across those Look & Feel screens in Calibre very recently, so I believe there's a way to do this property stripping already...

In Calibre, there is the Transform Styles tab (right next to the Styling tab):

Click image for larger version

Name:	Calibre.Look&Feel.TransformStyles.png
Views:	162
Size:	55.5 KB
ID:	189346

... but documentation is sparse + I don't exactly know how useful it would be (yet), since I'm typically dealing with all types of nonsense on a per-book level. (I do see Import/Export button + a GUI to create rules though.)

Right now, I do CSS cleanup manually (using regex) + multiple rounds of Calibre EPUB->EPUB conversions... until I'm satisfied and have a relatively clean base to work from.

But to have a quicker way to:
  • strip/consolidate CSS
  • compare CSS
  • convert/map to human-readable/standard class names

would be absolutely fantastic.

Many times, I'm just looking through tons and tons of cruft only to finally spot the single difference being a:

- font-variant: italic;

then I know: "Oh, this should just be a class="italic" (or <i> / <em>)."

Then I do a simple S&R or open up Diap's Toolbag and convert it.

Last edited by Tex2002ans; 09-21-2021 at 11:21 PM.
Tex2002ans is offline   Reply With Quote