View Single Post
Old 12-16-2021, 04:47 PM   #140
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 democrite View Post
If for example I wanted to change all possible span styles such as italic/bold to i/em or b/strong, and remove others, being able to run whatever is needed in one go, I think that'd be easier.
Cleaning up Relatively Normal Code

If I'm working from relatively normal code (like HTML out of Finereader), I have lots of Saved Searches like:

Code:
<span style="font-style:italic;">
to

Code:
<span class="italics">
Then, when I get my EPUB normalized to a basic set of classes:
  • italics
  • bold
  • smallcaps
  • ...

I do a few runs of TagMechanic to swap all:
  • <span class="italics"> -> <i>
  • <span class="bold"> -> <b>
  • ...

Cleaning up Ugly Code

For stuff like hundreds of random "calibre123" classes, I do something similar.

I go through, renaming them to the basic set ("italics", "bold", ...):

Code:
<p>This is an <span class="calibre123">italics</span> example and a <span class="calibre456">bold</span> example.</p>
Code:
<p>An <span class="italics">italics</span> example and a <span class="bold">bold</span> example.</p>
Then I do the usual few TagMechanic runs.

Side Note: I think the next version of Sigil is going to have some help on this front (at least I made KevinH aware of it).

You'd be able to Right-Click a class name in your code, and have Sigil rename the class for you. (Calibre currently has this functionality under Right-Click > Rename this class.)

That'd be able to accomplish a piece of TagMechanic's helpfulness right there in Sigil's Right-Click menu!

Another Trick I Use with Ugly Code

Throwing away useless classes.

Let's say there's a <span class="calibre1"> that has a transparent background + black text:

Code:
<p><span class="calibre1">This</span> <span class="calibre1">is</span> <span class="calibre1">ugly</span> <span class="calibre1">code</span> <span class="calibre1">that</span> <span class="calibre1">does</span> <i class="calibre99">nothing</i>.</p>
I just do sets of:

Search: <span class="calibre1">
Replace: <span>

Code:
<p><span>This</span> <span>is</span> <span>ugly</span> <span>code</span> <span>that</span> <span>does</span> <i class="calibre99">nothing</i>.</p>
After rounds of this, I run TagMechanic to completely delete all empty <span>s.

Code:
<p>This is ugly code that does <i class="calibre99">nothing</i>.</p>
This makes it so much easier to spot the actual changes that need to be made.

Then all that's left is a much smaller set of TagMechanic runs:

Code:
<p>This is ugly code that does <em>nothing</em>.</p>
- - - - - - - - - -

Side Note: And on some more random tricks/tips on cleaning up messy documents, I discussed a lot of things in this thread:

(RbnJrg asked about cleaning up a real CSS disaster.)

That topic spawned about a month of me pondering about it + privately discussing lots of potential power tools with KevinH.

A lot of that is now discussed in:

This will (hopefully) introduce more advanced CSS cleanup/merging... built right into Sigil.

Quote:
Originally Posted by DiapDealer View Post
Quote:
Originally Posted by democrite View Post
- concerning needing to select files to operate on, might an alternative be some file filter as is available with search and replace? [...]
This one is a non-starter, I'm afraid. Asked and answered. I have zero interest in changing the file selection process from the way it works now. Select the files in book browser; run the plugin. It only works on xhtml files and I have no interest in reinventing the wheel to enable file-selection from within the plugin, when the functionality already exists to pass the files selected in Book Browser to the plugin.
The Calibre version of this plugin works across all files by default, then has a checkbox for "Edit current file only".

Sigil's version works based on what files are selected in the Book Browser.

A similar "all files" request was definitely discussed many times over the years. (I don't feel like digging up all the posts, but even I mentioned it a few times).

... Anyway, if you want to run across all files by default, I recommend swapping it over to Calibre + Diap's Editing Toolbag.

I don't mind using either method, since I'm already going between Sigil/Calibre during various stages of cleanup.

Last edited by Tex2002ans; 12-16-2021 at 05:29 PM.
Tex2002ans is offline   Reply With Quote