07-24-2014, 12:51 PM | #31 |
creator of calibre
Posts: 43,871
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
FYI tomorrows calibre release has support for editor plugins.
http://manual.calibre-ebook.com/crea...t-book-plugins |
07-25-2014, 01:46 AM | #32 |
Grand Sorcerer
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Sort CSS plugin
Well, that was disgustingly easy. Well, it was once I actually read what Kovid had written about it. Then the hardest part was to find an icon*.
Because of a question in the Modify ePub thread about sorting the CSS, I decided to try an editor plugin. It is dumb. It simply adds a toolbar button. Press the button and it sorts each stylesheet on the selectors. Then it presents the differences. The plugin is attached. I have only tested it with the Qt5 beta code of calibre, but it should be OK with Qt4. I did this for curiosity more than any actual need I have. If there is any real interest, I'll open a thread to discuss it. * And I don't think I was very successful at that. |
Advert | |
|
07-25-2014, 02:07 AM | #33 |
Wizard
Posts: 1,760
Karma: 9918418
Join Date: Feb 2013
Location: Here on the perimeter, there are no stars
Device: Kobo H2O, iPad mini 3, Kindle Touch
|
Here's something I wouldn't mind seeing as an editor function, whether native or by plugin: a wrap/unwrap feature. The wrap feature would enable wrapping lines to a maximum length of N characters or less, and that's fairly simple. The harder part is the reverse, taking paragraphs that have been wrapped to that specification and removing the internal line breaks.
There's a decent Unwrap option in one of Notepad++'s plugins, and it uses blank lines as its "end of block" marker - but since EPUBs use XHTML, it ought to be possible to actually use the tags for that: "hey, this is an open-paragraph; let's find the corresponding close-paragraph!" Of course, there are always devils in the details, and there's some pretty horrible code floating around in some ebooks (like the heathens who use DIV instead of P for all their paragraphs), which strikes me as an excellent reason to make it an editor plugin (where you can see the results) instead of a general plugin. Just an idea, of course. It'd be nice to have, but I can always get by with doing a copy/paste to Notepad++ when needed. |
07-25-2014, 02:39 AM | #34 | |
Grand Sorcerer
Posts: 6,235
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
Quote:
|
|
07-25-2014, 03:05 AM | #35 |
Grand Sorcerer
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Glad you like it, but, there is a problem with it that someone else reminded me of. The order of the styles can be important. If a style gets redefined later in the file, the sorting could mess this up.
|
Advert | |
|
07-25-2014, 03:39 AM | #36 |
creator of calibre
Posts: 43,871
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
If you want to make it robust, you have to do a multisort, sorting primarily on selector specificity and secondarily on selector name. You can use the cssselect module to easily calculate selector specificities.
|
07-25-2014, 03:53 AM | #37 |
Grand Sorcerer
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Thanks, I'll have a look at that. The current sort is purely selector. And of course that doesn't work. Not all the style types have a selector. When I tested with the calibre portable, I hit an error with the "@namespace" that is in the stylesheet for the calibre user guide.
|
07-25-2014, 03:56 AM | #38 |
creator of calibre
Posts: 43,871
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
And dont forget that some rules can have multiple selectors, separated by commas.
CSS is a really poor language to modify in any robust fashion, that is one of the reasons that the calibre conversion flattens all css into classes. |
07-25-2014, 04:18 AM | #39 | |
Wizard
Posts: 1,760
Karma: 9918418
Join Date: Feb 2013
Location: Here on the perimeter, there are no stars
Device: Kobo H2O, iPad mini 3, Kindle Touch
|
Quote:
.calibre .calibre1 .calibre10 .calibre2 to this? .calibre01 .calibre02 .calibre03 .calibre10 (Intermediate classes omitted for brevity.) The leading zeroes just make it so much easier to make sure one doesn't accidentally catch the wrong target with a regex match; "calibre1" matches that, "calibre10", "calibre11", and so on. "calibre01" is much more solid. |
|
07-25-2014, 04:28 AM | #40 |
Wizard
Posts: 1,161
Karma: 1404241
Join Date: Nov 2010
Location: Germany
Device: Sony PRS-650
|
Only as a reminder, if you have files form PDF saved to docx or files from OCR the styles will increase often to more then two digits (I have seen a lot more in tests and it was sometimes up to four digits). Not saying this is a good thing - but stupid things happen.
|
07-25-2014, 04:32 AM | #41 | |
Wizard
Posts: 1,760
Karma: 9918418
Join Date: Feb 2013
Location: Here on the perimeter, there are no stars
Device: Kobo H2O, iPad mini 3, Kindle Touch
|
Quote:
|
|
07-25-2014, 04:42 AM | #42 |
Wizard
Posts: 1,161
Karma: 1404241
Join Date: Nov 2010
Location: Germany
Device: Sony PRS-650
|
I am with you. My intention was more an additional remark instead of please do not do this.
|
07-25-2014, 05:08 AM | #43 |
creator of calibre
Posts: 43,871
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Doing that increases the size of the css and the html files (something that affects everyone), for what is a benefit that helps only a few people.
|
07-25-2014, 05:42 AM | #44 | |
Wizard
Posts: 1,760
Karma: 9918418
Join Date: Feb 2013
Location: Here on the perimeter, there are no stars
Device: Kobo H2O, iPad mini 3, Kindle Touch
|
Quote:
Even without leading zeroes, though, is there any chance of tweaking the CSS sort order from 1-10-11-2-3 to 1-2-3-10-11? Should have no effect on the file sizes (compressed or not), and it actually puts the classes into the order in which they were constructed. |
|
07-25-2014, 05:52 AM | #45 |
creator of calibre
Posts: 43,871
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
That is how they are sorted
https://github.com/kovidgoyal/calibr...latcss.py#L581 and calibre-debug -c "from calibre.utils.icu import numeric_sort_key; print sorted('.calibre10 .calibre2'.split(), key=numeric_sort_key)" ['.calibre2', '.calibre10'] |