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 07-24-2014, 12:51 PM   #31
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: 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
kovidgoyal is offline   Reply With Quote
Old 07-25-2014, 01:46 AM   #32
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
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.
Attached Files
File Type: zip SortCSS.zip (18.4 KB, 237 views)
davidfor is offline   Reply With Quote
Advert
Old 07-25-2014, 02:07 AM   #33
Rev. Bob
Wizard
Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.
 
Rev. Bob's Avatar
 
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.
Rev. Bob is offline   Reply With Quote
Old 07-25-2014, 02:39 AM   #34
Terisa de morgan
Grand Sorcerer
Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.
 
Terisa de morgan's Avatar
 
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:
Originally Posted by davidfor View Post
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.
Thank you very much, it's quite interesting for me and it will go to my standard operations (remove unused styles, remove info about colors and fonts, check...)
Terisa de morgan is offline   Reply With Quote
Old 07-25-2014, 03:05 AM   #35
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Quote:
Originally Posted by Terisa de morgan View Post
Thank you very much, it's quite interesting for me and it will go to my standard operations (remove unused styles, remove info about colors and fonts, check...)
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.
davidfor is offline   Reply With Quote
Advert
Old 07-25-2014, 03:39 AM   #36
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: 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.
kovidgoyal is offline   Reply With Quote
Old 07-25-2014, 03:53 AM   #37
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Quote:
Originally Posted by kovidgoyal View Post
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.
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.
davidfor is offline   Reply With Quote
Old 07-25-2014, 03:56 AM   #38
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: 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.
kovidgoyal is offline   Reply With Quote
Old 07-25-2014, 04:18 AM   #39
Rev. Bob
Wizard
Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.
 
Rev. Bob's Avatar
 
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:
Originally Posted by kovidgoyal View Post
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.
Speaking of which, is there any chance of getting the current calibre CSS output switched from this:

.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.
Rev. Bob is offline   Reply With Quote
Old 07-25-2014, 04:28 AM   #40
Divingduck
Wizard
Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.
 
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.
Divingduck is offline   Reply With Quote
Old 07-25-2014, 04:32 AM   #41
Rev. Bob
Wizard
Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.
 
Rev. Bob's Avatar
 
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:
Originally Posted by Divingduck View Post
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.
Well, sure. I'm just saying that numbering all the classes (instead of not numbering the first) and using leading zeroes (however many are needed) are both useful things.
Rev. Bob is offline   Reply With Quote
Old 07-25-2014, 04:42 AM   #42
Divingduck
Wizard
Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.Divingduck ought to be getting tired of karma fortunes by now.
 
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.
Divingduck is offline   Reply With Quote
Old 07-25-2014, 05:08 AM   #43
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: 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.
kovidgoyal is offline   Reply With Quote
Old 07-25-2014, 05:42 AM   #44
Rev. Bob
Wizard
Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.Rev. Bob ought to be getting tired of karma fortunes by now.
 
Rev. Bob's Avatar
 
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:
Originally Posted by kovidgoyal View Post
Doing that increases the size of the css and the html files (something that affects everyone),
On the uncompressed level, true enough. Once the files are recompressed and saved, not so much.

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.
Rev. Bob is offline   Reply With Quote
Old 07-25-2014, 05:52 AM   #45
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: 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']
kovidgoyal is offline   Reply With Quote
Reply


Forum Jump


All times are GMT -4. The time now is 11:53 AM.


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