09-06-2016, 02:17 AM | #1 |
Wizard
Posts: 2,608
Karma: 3000161
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
|
A proposal: help sorting css stylesheet
Hi
When we try to tweak some EPUB, we frequently have to deal with long and confuse stylesheet, sometimes made up with aggregates built differently. I wish this could be done within the Calibre Editor. There is an "unofficial" Calibre plugin about it (Sort CSS.zip). I wish I had a menu entry in the Editor which would complement the "beautify" tool and help me sort cleanly the stylesheet. This way I could also easily spot duplicates. The sorting rule would take care of the nature of the items and then use alphabetic order (what else?) 1. elements (with @ elements coming first like @page or @font-face). If several elements are grouped, the first one determine its alphabetic place. If elements (like p) have several selectors, these also would be sorted out alphabetically. 2. class selectors (beginning with a coma) If the pertaining element is left unspecified, the class selectors shoud be placed after all the elements. 3. ids (beginning with a #) I think this way we could sort at least 95% of the content of any stylesheet 4. . ? |
09-06-2016, 03:18 AM | #2 |
creator of calibre
Posts: 43,990
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Since there is already a plugin to do that, why do you need builtin functionality? Plugins are perfectly capable of adding buttons to the editor UI.
|
Advert | |
|
09-06-2016, 04:06 AM | #3 |
Wizard
Posts: 2,608
Karma: 3000161
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
|
Because the plugin, though its age (two, three years?) is far from complete and can't do what's is described. And it's not "official" (so not really reliable).
|
09-06-2016, 06:06 AM | #4 |
Resident Curmudgeon
Posts: 74,526
Karma: 129670952
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
[QUOTE=roger64;3386203]Hi
When we try to tweak some EPUB, we frequently have to deal with long and confuse stylesheet, sometimes made up with aggregates built differently./quote] The first thing to do is remove unused CSS classes. Calibre does it best as it also removed unused CSS classes from the HTML code. Then you can see what's left. By removing unused CSS classes, you can take a CSS file with many classes that looks unwieldy and make it into something a lot easier to deal with. |
09-06-2016, 08:17 AM | #5 | |
Grand Sorcerer
Posts: 24,906
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Quote:
It does a very simple sort on the selectors. I started work on a more intelligent sort, but didn't continue. What I started was something like what roger6 is asking for. I think I hit some issues with the how to do organise the selectors, and as it wasn't something I was really interested in, I stopped. I might return to it, but, there are lots of other things I'm more interested in. If someone else wants to take it up, I'd be happy to hand it over. |
|
Advert | |
|
09-06-2016, 08:54 AM | #6 |
creator of calibre
Posts: 43,990
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
I dont see how you can sort CSS rules at all, in the general case. For example,
.class2 { color: red} .class1 { color: green} If you sort that to .class1 { color: green} .class2 { color: red} You will have changed the color of any element that has both those selectors apply to it. Before the sort, it would be green, after the sort it would be red. This is because the specificity of a selector depends on its position in the stylesheet with respect to other selectors. |
09-06-2016, 09:46 AM | #7 |
Grand Sorcerer
Posts: 24,906
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
And that's one of the other problems. If used very carefully, it's probably OK, but it could easily mess things up.
|
09-06-2016, 10:08 AM | #8 |
Wizard
Posts: 2,608
Karma: 3000161
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
|
Hi
There are for example use cases when you add a custom stylesheet to be able to edit quickly any ebook. Once the work is done, once the unused rules have been deleted, you may wish to unify and clean the style sheet. We already can do it joining together two different stylesheet using the Calibre Editor. To day, this is done mainly putting the text of the second one under the text of the first one. However the end result usually looks like a mess even if it's not... If some kind of sorting allows you to detect duplicates, I think it will be a progress. It will be useful practically even if it can trigger 0.001% of mistakes of the kind you referred to. |
09-06-2016, 11:29 AM | #9 |
Grand Sorcerer
Posts: 6,268
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
The actual sorting allows you to detect duplicates. It doesn't avoid you a manual movement later but that is a minor annoyance. My OCD is more annoyed by alpha sort instead of numeric sort after "calibre", but I can live with that.
|
09-06-2016, 12:11 PM | #10 | |
Resident Curmudgeon
Posts: 74,526
Karma: 129670952
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
|
|
09-06-2016, 12:48 PM | #11 | |
Grand Sorcerer
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Quote:
Code:
<p class="class2 class1">This text should be green</p> |
|
09-06-2016, 01:52 PM | #12 |
Well trained by Cats
Posts: 29,944
Karma: 55705602
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
One of the reasons I use Sigil is CSS sorting is NOT needed. It has a Goto link or style that works in most cases, even when there are multiple stylesheets in the book.
Cases where it (Sigil) does not work perfectly doubly (or more) defined: it goes to first found Defined in more than one sheet. Goes to the one in the First Linked sheet the case Jackie_W shows has even bigger issues, 'Delete unused styles' will REMOVE the second style as unused NB Sigil also destroys @Amazon type CSS entries CLEAN and sorting should always be used with care (and a prior save) The Report tool may help you decide. But there are so many 100% valid (HTML and CSS usage) cases that automation will never get it 100% |
09-06-2016, 02:20 PM | #13 |
creator of calibre
Posts: 43,990
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
So does calibre, in fact calibre has Live CSS which includes that function and is much more powerful, in that it shows you all the CSS style rules that apply to the current html element you are editing as you edit.
Last edited by kovidgoyal; 09-06-2016 at 02:23 PM. |
09-06-2016, 02:56 PM | #14 | |
Well trained by Cats
Posts: 29,944
Karma: 55705602
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
I looked at Live CSS and went ???, this seemed like another 'Inspector' (which I use when I just can't figure WHY I am getting the results Thanks again |
|
09-06-2016, 03:01 PM | #15 |
creator of calibre
Posts: 43,990
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Note that you can click on the stylesheet names in blue in the Live CSS Panel. This allows you to edit the relevant CSS file, with the cursor pre-positioned at the rule definition as well. It even works for rules defined inside <style> tags and style attributes.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
stylesheet.CSS anyone? | ProDigit | ePub | 81 | 12-26-2015 01:43 PM |
User agent stylesheet: a proposal | roger64 | Editor | 4 | 12-27-2014 02:00 AM |
Converting cm to em in css stylesheet | roger64 | ePub | 41 | 06-13-2014 01:00 PM |
How to maintain a global CSS stylesheet | amoroso | Sigil | 7 | 07-18-2010 08:37 PM |
Where is the stylesheet.css? | roger64 | Sigil | 4 | 03-23-2010 02:12 PM |