10-16-2020, 08:03 AM | #1 |
Hedge Wizard
Posts: 800
Karma: 19999999
Join Date: May 2011
Location: UK/Philippines
Device: Kobo Touch, Nook Simple
|
Merge Identical CSS Rules
I do not know if I have missed something (again).
I was editing an ePub yesterday The html was awful (stupidly convoluted) and I was simplifying it. As I was going through the "stylesheet", I noticed a lot of the defined styles were identical except for their names. My immediate thought was "Doesn't the Removed Unused CSS Rules" fix this". I had run it on opening the ePub so I knew the option to Merge Identical CSS Rules option was ticked. To check matters I created a dummy ePub which had several dozen pairs of styles which were identical except for their names. I also created an empty paragraph for each CSS style addimg class="dunnystylename" so each style was mentioned in the text. I then ran the plugin. NONE of the identical CSS styles was merged. I then repeated the operation with the Merge box unticked (just in case) and got the same result. Has this feature been depreciated, is it a bug or is it my setop? I am on Windows 10 Enterprise - 64bit, calibre version 5.1 Last edited by Thasaidon; 10-16-2020 at 08:05 AM. Reason: typo |
10-16-2020, 09:04 AM | #2 |
Guru
Posts: 766
Karma: 6528026
Join Date: Sep 2012
Device: Kobo Elipsa
|
I believe doing an epub to epub conversion will merge identical classes. But I hope merging won't be incorporated into "Remove Unused CSS Rules." I sometimes use identical CSS rules with different names in different sections of an epub. I would prefer not to see a style named "dedication" or "toc" in the middle of a chapter where "center" makes more sense to my human brain.
|
Advert | |
|
10-16-2020, 09:18 AM | #3 | |
Hedge Wizard
Posts: 800
Karma: 19999999
Join Date: May 2011
Location: UK/Philippines
Device: Kobo Touch, Nook Simple
|
Quote:
I use ny own stylesheet with my own name for each style so do not care about the original style names. |
|
10-16-2020, 09:55 AM | #4 |
creator of calibre
Posts: 43,843
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Merging of rules merges rules that have identical selectors, not rules that have different selectors but identical properties.
|
10-16-2020, 10:19 AM | #5 |
Resident Curmudgeon
Posts: 73,894
Karma: 128597114
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
To merge the same classes in CSS, load the eBook into the editor. Then from the tools menu, select Remove unused CSS rules. This will allow you to merge and also remove unused classes. You can deselect to remove unused classes and just merge if you want. But give how a lot of ePub can have hundreds of unused classes, I would not deselect to remove unused classes.
|
Advert | |
|
10-16-2020, 12:55 PM | #6 |
Not Quite Dead
Posts: 191
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
@Thasaidon:
Read the pasted thread below. It may be pertinent and has a regex that can work in your cleaning operation: remove unused CSS rules https://www.mobileread.com/forums/sh...d.php?t=322973 |
10-16-2020, 10:50 PM | #7 |
Hedge Wizard
Posts: 800
Karma: 19999999
Join Date: May 2011
Location: UK/Philippines
Device: Kobo Touch, Nook Simple
|
I apologise I think I have misled some people as to what I was asking. I should have KISS'ed it (Keep It Simple Stupid)
Simply put, a CSS nay contain the following rules .chapterHeader { height: 60px; border: 1px solid #000; display: block; margin-bottom: 20px; background-color: #FFF } .chaprHd { height: 60px; border: 1px solid #000; display: block; margin-bottom: 20px; background-color: #FFF } I expected Merge Identical CSS Rules to change this to something like .chaprHd, chapterHeader { height: 60px; border: 1px solid #000; display: block; margin-bottom: 20px; background-color: #FFF } i.e. To produce a stacked rule and delete the two original rules From a very hazy memory of when this feature was introduced this is what I thought it did, If I understand Kovid's answer to my rambling question , correctly, the answer is NO. It does not work like that. If that is the case would a plugin or Regex guru would like to help. The reason I would find this useful is in the bBook, I mentioned. It had over 1000 lines in the CSS, all used, which included duplicated rule sets, each having a unique Selector name. Reducing clutter by having a smaller number of rule sets with stacked Selectors would be easier to follow. I hope this clears up any confusion I causedr Last edited by Thasaidon; 10-16-2020 at 10:52 PM. |
10-17-2020, 02:43 PM | #8 | |
Running with scissors
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
|
Quote:
One of my peeves is that when the classes are stacked like that, an unused class, for example your .chaprHd, isn't removed when it's not used in the html. |
|
10-17-2020, 08:41 PM | #9 | |
Hedge Wizard
Posts: 800
Karma: 19999999
Join Date: May 2011
Location: UK/Philippines
Device: Kobo Touch, Nook Simple
|
Quote:
The book I was talking about while not having a span round every word was very close to it. Last edited by Thasaidon; 10-17-2020 at 08:49 PM. |
|
10-17-2020, 11:27 PM | #10 |
creator of calibre
Posts: 43,843
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
|
10-18-2020, 12:30 AM | #11 | |
Hedge Wizard
Posts: 800
Karma: 19999999
Join Date: May 2011
Location: UK/Philippines
Device: Kobo Touch, Nook Simple
|
Quote:
Your generosity and ability to turn code around never ceases to amaze me. You have my deepest respect. I bet the code is still dizzy from being turned around |
|
10-18-2020, 09:30 AM | #12 | ||
Not Quite Dead
Posts: 191
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
Quote:
Quote:
|
||
10-18-2020, 10:39 AM | #13 | |
Hedge Wizard
Posts: 800
Karma: 19999999
Join Date: May 2011
Location: UK/Philippines
Device: Kobo Touch, Nook Simple
|
Quote:
You are free to disagree with my personal tastes What I do with my books is to replace the code in the text files and the CSS file to something that suits me. From reading what people have said in the past in these forums I think many people do the same, I identify those rules in the original CSS which relate to e.g. Chapter headings. Then remove the html round the headings in the text (spans, italic bold whatever) leaving just H1 or H2 tags Hi and h2 are selectors in my CSS. In the example I gave I reduced the number of lines in the CSS from about a thousand to well below a hundred. I like minimalist code and dislike huge numbers of almost identical rules that I think add nothing to the look of the book. The difference between some of these rules is often such that I find it difficult distinguish/impossible between them on the page. I just eliminate these (to me ) trivial, unnecessary differences and use a single rule for all of them. Having the selectors stacked means I know, there are groups of selectors in the html that use the same ruleset. I do not have to search through the CSS file to find which rulesets are identical. You may be right it may not help much but I have a lot of books that I want to change to my visual/coding tastes. |
|
10-18-2020, 12:43 PM | #14 | |
Not Quite Dead
Posts: 191
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
Quote:
Last edited by Brett Merkey; 10-18-2020 at 12:46 PM. |
|
10-18-2020, 12:44 PM | #15 |
Running with scissors
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
|
I used to try and clean up the html but in my opinion it's more work than is necessary, for my needs. I now take a big sledgehammer and delete all of the original css and replace it with my minimal css as explained here. After "fixing" the css this way all that crap just stops creating problems (although it requires self discipline to not look too much at their horrid html). I'll still remove those spans that are around every word or the classless ones around paragraphs, and I bold the chapter titles when they use p tags instead of h tags.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
remove unused CSS rules | rjwse@aol.com | Editor | 13 | 09-18-2019 09:39 AM |
CSS Rules | deback | Conversion | 1 | 01-31-2019 03:59 PM |
CSS rules | Sebastian Kane | Calibre | 1 | 07-19-2017 07:25 AM |
Remove unused CSS Rules | Divingduck | Editor | 2 | 06-21-2014 07:51 AM |
Conditional CSS rules | Jellby | ePub | 10 | 01-20-2009 08:32 AM |