MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   [Plugin] cssUndefinedClasses (https://www.mobileread.com/forums/showthread.php?t=332317)

wrCisco 08-13-2020 01:14 AM

[Plugin] cssUndefinedClasses
 
2 Attachment(s)
Hi to all,

as requested some weeks ago, here is a plugin that deletes from the xhtml all classes and ids that are not referenced anywhere in the stylesheets (nor in fragment identifiers in href or other attributes, in the case of ids).

There is a graphical interface that lets the user choose what they want to remove and what they want to keep.

I tried to adjust the colors of backgrounds and texts to keep it all readable and not too ugly in the various dark modes, but I couldn't test the plugin on a Mac (and I know Tcl/Tk and Mac don't always get along very well...).

The parser css used by the plugin is css_parser/cssutils, the parser xhtml is gumbo (adapter for sigil_bs4), all provided by Sigil installers.

For now I tested the plugin with Sigil 1.2 and 1.3 on Linux Mint, Manjaro, Win7 and Win10.

I uploaded the first version of the plugin as a beta (needs some more testing), let me know if you encounter any problems, thanks!

The license of the plugin is the GPL v3 or any later version.

Changes:
Spoiler:
v0.2.0:
- the search for fragment identifiers has been extended to all xml files (ncx, media overlays...);
- the list of attributes in which to search for fragment identifiers is user customizable in the preferences pane, and the default values are href, epub:textref and src;
- another option for the user in the preferences pane is to restrict the search for classes and IDs to be removed to only a selected subset of files.
v0.2.1:
- flash bug fix (in v0.2.0 fragment identifiers were searched for only in selected xhtml files).
v0.2.2
- added an icon for the plugin;
- less rigid parsing of css selectors: now the plugin process also some invalid names for classes and ids in the stylesheets (although invalid, the plugin shouldn't ignore them).

odamizu 08-13-2020 02:44 AM

:thanks: I use Calibre to do this and am happy to now have this functionality in Sigil. (I also love your cssRemoveUnusedSelectors plugin :) )

KevinH 08-13-2020 10:02 AM

Thank you! I added it to the Sigil Plugin Index.

wrCisco 08-14-2020 03:47 PM

Quote:

Originally Posted by odamizu (Post 4022429)
:thanks: I use Calibre to do this and am happy to now have this functionality in Sigil. (I also love your cssRemoveUnusedSelectors plugin :) )

Quote:

Originally Posted by KevinH (Post 4022529)
Thank you! I added it to the Sigil Plugin Index.

Thanks for the appreciation. I just uploaded a second version of the plugin with some improvement and a preferences panel for the user.

David Kudler 08-14-2020 03:53 PM

Ah! Nice. I too have either resorted to sloppy Regex or Calibre to take care of this. Thanks!

wrCisco 08-22-2020 02:15 PM

Quote:

Originally Posted by David Kudler (Post 4022988)
Ah! Nice. I too have either resorted to sloppy Regex or Calibre to take care of this. Thanks!

I'm glad it helps.


I just uploaded version 0.2.2 of the plugin, with an icon for displaying in Sigil and in the window manager (if the 'manager' allows it).
Also, the plugin now accepts some invalid class and id names found in css selectors (even if they are invalid, the plugin should not ignore them entirely).


All times are GMT -4. The time now is 08:40 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.