![]() |
#1 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 73
Karma: 7130
Join Date: Apr 2015
Device: PRS-T3
|
Removal of undefined classes from text
I noticed a strange behaviour in calibre 4.19 for the following situation:
In the text: both <p class="center">... and <div class="center">... are used In the corresponding style file: Only p.center is defined but a definition of div.center is not present. Therefore, not formatting is applied to the <div class="center"> passages. When I use the button in the editor for removing undefined classes (my German translation uses "removing unused classes from the text", but "undefined" seems more appropriate) from the text, it does not report any undefined/unused classes in the text. Shouldn't it remove or at least indicate that div.center is not defined? I think that previous versions did this, but I'm not sure. Regards, McDummy |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,323
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
It has always done that. It does not apply actual selectors, it simply looks for classes in a selector and if the class name exists in some selector, it is marked as used.
|
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 73
Karma: 7130
Join Date: Apr 2015
Device: PRS-T3
|
Quote:
Many ebooks, e.g., from gutenberg.org, contain style files do do not include all necessary definitions. Making the class removal function selector/element dependent would help to find and add missing definitions. |
|
![]() |
![]() |
![]() |
#4 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,323
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Removing unused classes is about removing classes from HTML not style files. Removal of unused style rules will remove all style rules that are actually unused.
|
![]() |
![]() |
![]() |
#5 | |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 73
Karma: 7130
Join Date: Apr 2015
Device: PRS-T3
|
Quote:
To have this check function, I let the editor remove unused classes and then look at the removal classes to see what classes are used but do not have a corresponding definition in a style file. However, if this function only checks if a class is defined for some selector, then it is extremely misleading and inconvenient. For instance, assume you only have <div class="center"> in the text an only p.center in the style file. When you press the button once with all options checked, it removes the p.center from the style file, but does not show that classes are unused in the html. When you press it afterwards again, it shows you that the "center"-class is unused in the html and removs the class from the html. In addition, if the creator of the ebook made a mistake and defined p.center but forgot to define div.center, he won't be able to notice that a defintion is missing. |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,323
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
If you find the function misleading, dont use it. It's at the sweetspot of utility vs performance for me.
|
![]() |
![]() |
![]() |
#7 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,687
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
If you find that <p class="center"> and <div class="center"> are the same class, just remove the p from p.class in the Ss and you'll have fixed the <div>.
|
![]() |
![]() |
![]() |
#8 | |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 73
Karma: 7130
Join Date: Apr 2015
Device: PRS-T3
|
Quote:
First of all, a p.center defintion has no effect on a div passages. Secondly, if you have 100 <div class="center"> occurences and only one of <p class="center"> in the html and a style file that only has a definition for p.center but none for div.center, the tool would remove none of the 101 classes. On the other hand, if you have 100 <div class="center"> passages and no <p class="center"> in the html and the same style file as above, the tool would remove all 100 classes. |
|
![]() |
![]() |
![]() |
#9 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,687
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
|
|
![]() |
![]() |
![]() |
#10 | |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 73
Karma: 7130
Join Date: Apr 2015
Device: PRS-T3
|
Quote:
Therefore, although the <div class="center"> is not doing anything, since the corresponding definition is missing in the css, calibre is not removing the "center" class from <div class="center"> since the CSS contains a p.center defintion, which, as pointed out, has no effect on the <div class="center"> So when you use the calibre tool, you assume that all classes in the html have a corresponding defintion in the CSS even if this is not the case. P.S. I didn't botch the CSS. I downloaded the book and checked the book for errors. During the check I noticed by coincidence that the html contains both <div class="center"> and <p class="center"> and that calibre does not remove the class from <div class="center">, since the CSS contained a p.center definition. |
|
![]() |
![]() |
![]() |
#11 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,323
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
|
![]() |
![]() |
![]() |
#12 |
Nameless Being
|
Could "Check book" be altered to alert one when a class is called that has not been defined in a stylesheet? Much like it presently does when an image, present in the book, has not been linked in a file.
|
![]() |
![]() |
#13 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,031
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
|
![]() |
![]() |
![]() |
#14 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 73
Karma: 7130
Join Date: Apr 2015
Device: PRS-T3
|
This gives the same result. When different elements/selectors use classes with the same name in the html, but only one of the classes is defined in the css, the report (both style classes and style rules) show that no unused class exist.
You have to go through all classes in the style classes report to check, if each class appearing in the html has a corresponding definition in the css. I've now switched to Sigil. The Sigil report gives a better overview of the used/defined classes. So far, it does not provide an automatic deletion of unused classes, but there seems to be some work on implementing this tool. Last edited by mcdummy; 07-03-2020 at 03:06 AM. |
![]() |
![]() |
![]() |
#15 | |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,323
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Quote:
Code:
:not(.center) Last edited by kovidgoyal; 07-03-2020 at 05:38 AM. |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Pseudo classes to be deleted as unused classes | Leonatus | Sigil | 2 | 09-23-2018 09:12 AM |
Is there way to list undefined classes? | phossler | Editor | 10 | 07-29-2018 09:33 PM |
Pseudo classes with classes | Macsurfcat | ePub | 4 | 01-07-2016 04:00 AM |
PRS-600 Sony library - Error undefined | omk3 | Sony Reader | 13 | 01-22-2010 10:52 AM |
Good Article on Amazon's Text to speech Removal | pippin65 | Amazon Kindle | 12 | 03-03-2009 10:54 AM |