Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 06-24-2020, 04:30 AM   #1
mcdummy
Connoisseur
mcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the rough
 
mcdummy's Avatar
 
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
mcdummy is offline   Reply With Quote
Old 06-24-2020, 06:16 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
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.
kovidgoyal is offline   Reply With Quote
Advert
Old 06-24-2020, 07:41 AM   #3
mcdummy
Connoisseur
mcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the rough
 
mcdummy's Avatar
 
Posts: 73
Karma: 7130
Join Date: Apr 2015
Device: PRS-T3
Quote:
Originally Posted by kovidgoyal View Post
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.
That's rather misleading, since the button for removing unused classes gives the impression that a style file contains all class definitions that are necessary for an ebook, if none is removed.

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.
mcdummy is offline   Reply With Quote
Old 06-24-2020, 07:43 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
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.
kovidgoyal is offline   Reply With Quote
Old 06-24-2020, 08:00 AM   #5
mcdummy
Connoisseur
mcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the rough
 
mcdummy's Avatar
 
Posts: 73
Karma: 7130
Join Date: Apr 2015
Device: PRS-T3
Quote:
Originally Posted by kovidgoyal View Post
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.
Removing unused classes from HTML is what I want. Basically, it should be more a check function to see if all classes required in the html are defined.

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.
mcdummy is offline   Reply With Quote
Advert
Old 06-24-2020, 10:03 AM   #6
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
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.
kovidgoyal is offline   Reply With Quote
Old 06-24-2020, 10:43 AM   #7
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
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>.
JSWolf is offline   Reply With Quote
Old 06-24-2020, 12:11 PM   #8
mcdummy
Connoisseur
mcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the rough
 
mcdummy's Avatar
 
Posts: 73
Karma: 7130
Join Date: Apr 2015
Device: PRS-T3
Quote:
Originally Posted by kovidgoyal View Post
If you find the function misleading, dont use it. It's at the sweetspot of utility vs performance for me.
Basically, without differentiating between, for instance, p and div classes/selector/elements in the style file, the whole tool is pointless.

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.
mcdummy is offline   Reply With Quote
Old 06-24-2020, 12:40 PM   #9
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
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:
Originally Posted by mcdummy View Post
Basically, without differentiating between, for instance, p and div classes/selector/elements in the style file, the whole tool is pointless.

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.
It's not Calibre's fault you botched the CSS. <div class="center"> is going to do nothing because you don't have any class in the CSS for that.
JSWolf is offline   Reply With Quote
Old 06-24-2020, 01:06 PM   #10
mcdummy
Connoisseur
mcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the rough
 
mcdummy's Avatar
 
Posts: 73
Karma: 7130
Join Date: Apr 2015
Device: PRS-T3
Quote:
Originally Posted by JSWolf View Post
It's not Calibre's fault you botched the CSS. <div class="center"> is going to do nothing because you don't have any class in the CSS for that.
That's the basic point: calibre is happy if any definition for a class name (in my example p.center) used in the html exists in the css, even if the class definition in the css has no effect on other elements using a class with the same name (<div class="center"> in my example).

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.
mcdummy is offline   Reply With Quote
Old 06-24-2020, 02:09 PM   #11
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,323
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Quote:
Originally Posted by mcdummy View Post
Basically, without differentiating between, for instance, p and div classes/selector/elements in the style file, the whole tool is pointless.
If you find it pointless, feel free to not use it. The rest of us shall continue doing so.
kovidgoyal is offline   Reply With Quote
Old 07-02-2020, 07:47 PM   #12
Ted Friesen
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.
  Reply With Quote
Old 07-02-2020, 09:28 PM   #13
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
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
Quote:
Originally Posted by Ted Friesen View Post
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.
Tools: Reports: Look at Style Classes and Style Rules
theducks is offline   Reply With Quote
Old 07-03-2020, 02:43 AM   #14
mcdummy
Connoisseur
mcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the roughmcdummy is a jewel in the rough
 
mcdummy's Avatar
 
Posts: 73
Karma: 7130
Join Date: Apr 2015
Device: PRS-T3
Quote:
Originally Posted by theducks View Post
Tools: Reports: Look at Style Classes and Style Rules
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.
mcdummy is offline   Reply With Quote
Old 07-03-2020, 05:20 AM   #15
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,323
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Quote:
Originally Posted by mcdummy View Post
So far, it does not provide an automatic deletion of unused classes, but there seems to be some work on implementing this tool.
I will be astonished if they do. You cannot in general conclude a class is unused if it exists in any selector. For a trivial example:

Code:
:not(.center)
This rule will not match <p class="center"> but the class is still used, since the elements that selector matches will change if you remove the class.

Last edited by kovidgoyal; 07-03-2020 at 05:38 AM.
kovidgoyal is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 04:16 PM.


MobileRead.com is a privately owned, operated and funded community.