![]() |
#1 |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 166
Karma: 474196
Join Date: Jan 2011
Location: Canada
Device: Kobo Libra 2
|
Quick way to remove all class invokations for missing classes?
I couldn't find this in search, but I'm basically wondering if there's a way to basically do the inverse of the "Delete unused stylesheet selectors" function.
I'm converting over a detailed game guide that originally consisted of several hundred Google docs, which I had downloaded as html and imported to Sigil. I've done a lot of the work in converting over headers, tables, and whatnot, but nearly every paragraph is either classed, or has classed spans that are unneeded due to the conversion process. I can't just do a quick S&R because the class names are named differently in each of those files, and there are some that colour the text that I'd like to keep. So what I would ideally like to do is go through the styles, which are currently in the file header, rename the ones that don't change the text colour (i.e. from "c\d+", to "XXDELETEXX" or somesuch), then use a function to find any <p>, <span>, etc that call a now-disconnected class and remove it. For a more specific example, lets say I have: Code:
<head> <style type="text/css"> .c2 { color: #000000; font-weight: 400; } .c26 { color: #ff0000; } .c73 { font-weight: 400; } </style> </head> <body> <p class="c26">red</span></p> <p><span class="c2 c73 c26">red and others</span></p> <li class="c2">only others</li> </body> Code:
<head> <style type="text/css"> .DELETEME { color: #000000; font-weight: 400; } .c26 { color: #ff0000; } .DELETEME { font-weight: 400; } </style> </head> <body> <p class="c26">red</span></p> <p><span class="c2 c73 c26">red and others</span></p> <li class="c2">only others</li> </body> Code:
<head> <style type="text/css"> .DELETEME { color: #000000; font-weight: 400; } .c26 { color: #ff0000; } .DELETEME { font-weight: 400; } </style> </head> <body> <p class="c26">red</span></p> <p><span class="c26">red and others</span></p> <li>only others</li> </body> Thanks in advance for any help! |
![]() |
![]() |
![]() |
#2 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,029
Karma: 144284074
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
|
![]() |
![]() |
![]() |
#3 |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 166
Karma: 474196
Join Date: Jan 2011
Location: Canada
Device: Kobo Libra 2
|
I use that plugin often, and that's how I'd do the cleanup (removing the DELETEMEs in my example) but to my knowledge it doesn't check if a class reference is defined or not.
In my example, renaming the classes would disconnect the reference to the class from the class definition, so the class c2 wouldn't connect to anything, since its definition was renamed to DELETEME. I'd like to be able to find all of those undefined class reference and remove them. |
![]() |
![]() |
![]() |
#4 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 808
Karma: 2416112
Join Date: Jan 2017
Location: Poland
Device: Various
|
You probably need this plugin – cssUndefinedClasses.
Last edited by BeckyEbook; 09-29-2023 at 01:38 PM. |
![]() |
![]() |
![]() |
#5 | |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 166
Karma: 474196
Join Date: Jan 2011
Location: Canada
Device: Kobo Libra 2
|
Quote:
|
|
![]() |
![]() |
![]() |
#6 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,029
Karma: 144284074
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
You can use TagMechanic to get rd of unwanted classes in the HTML and use cssUndefinedClasses to get rid of unused classes after you've dumped the unwanted classes.
I start by deleting any unwanted HTML. Then I remove some unwanted classes if there are any that I've noticed right away. I remove unused classes and then I add in my small list of classes. When I am done, I remove any other classes I've made unused. When I am done, all CSS and all classes in HTML as in use. |
![]() |
![]() |
![]() |
#7 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
Quote:
This would merge all dozens/hundreds of CSS files into unique classes. From there, you would use the "surgical" approach I described in: this would let you find/merge all the "duplicate" classes in sucessive conversions. Since 2021, KevinH has also added that cleanup functionality into Sigil too! It's called the "CSSToolbox", and I described it in more detail here: |
|
![]() |
![]() |
![]() |
#8 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,680
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
![]() KevinH's RemoveInLineStyles plugin might also be helpful, if the source files also contain inline styles. |
|
![]() |
![]() |
![]() |
#9 |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 166
Karma: 474196
Join Date: Jan 2011
Location: Canada
Device: Kobo Libra 2
|
So cssUndefinedClasses wasn't ideal since there were a lot of duplicate style classes, and it wouldn't remove them unless every definition was gone. For example, several pages would have a defined "c1" class, but in some cases c1 would style the text's color to blue (something I intended to keep, albeit defined in a common stylesheet), while in others it would set the left margin to 0em (something I wanted gone).
Anyway, I had to do a lot of the work manually anyway, but cssUndefinedClasses sure helped a lot with the final cleanup steps. |
![]() |
![]() |
![]() |
Tags |
classes, clean-up, replace, styles |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Remove-tag when class contains a whitespace | Villard | Recipes | 4 | 07-09-2023 03:08 AM |
Quick way to remove multiple libraries? | Rellwood | Library Management | 2 | 06-19-2022 06:14 PM |
find missing classes | kcarscadden | Editor | 4 | 12-10-2019 08:16 PM |
Remove unused class attributes | phossler | Editor | 15 | 01-26-2016 01:06 PM |
How to remove multiple class attribute from div | lrui | Recipes | 4 | 08-13-2012 09:47 PM |