Quote:
Originally Posted by dgatwood
Exactly. You can trivially get rid of the complex selectors by just replacing them with an arbitrary class name, then getting all the elements that match the original selector, and adding that class name to each of them. From there, the remaining mess is ensuring that each element has exactly one class name.
|
Excellent summary.
I'm building out a Node module on github that I dubbed
allscribe, intended to serve as a library for various ebook processing tasks. This KF7 business is the first thing I'm adding to it.
The first part (selector simplification into classes) is done, and the tests are passing. I'll be moving onto the class de-duping next, and I can report when I'm done. The idea is that you can do something like this:
Code:
var book = openEpub('/Documents/Books/Magnum-Opus');
var clone = book.clone(book.path + '_copy');
clone.simplifyCSS();
(Not that you need this lib, dgatwood, what with your whole perl setup, but maybe someone will find it useful.)
Quote:
Originally Posted by Turtle91
Aren't multiple classes defined in the ePub spec? Shouldn't a compliant reader/app be able to handle <p class="super duper"> in exactly the way you describe...combining the two class's css with the class listed first given higher priority? I rarely use multiple classes, but it seems Sigil and Marvin handle them just fine.
Is this just a work around for kindle's shortcomings rather than an ePub issue??
|
Yep, precisely. Obviously this thread is about ePubs originally, but we sorta segued into how to format ePubs in a way that they can be converted into KF7 without breaking into a million pieces. Here was dgatwood's earlier post:
Quote:
Originally Posted by dgatwood
I'm not producing the KF7 content myself. That list is what I had to do to my EPUB source just to make the latest version of Kindlegen convert it properly to KF7/KF8. For KF7, Kindlegen converts the CSS into HTML markup, but does it very badly, with a CSS parser that doesn't properly handle selectors containing multiple elements, multiple class names on single elements, lists of selectors applied to a single rule set, etc., resulting in all sorts of joy for those of us who routinely use nontrivial CSS.
|
Ah, dgatwood (er, can I just say David? I read some of your blog, btw

) I noticed in this earlier post that you said "lists of selectors applied to a single rule set", as in
body, span, p { color:red; }, but then later you said comma-separated selectors weren't an issue. I'm guessing your memory's hazy on this one? I'm obviously relying on your experience for all this, so forgive me for being such a lawyer over your comments.
I guess if I really wanted to get serious about this, I'd build a testing framework that ran things through Kindlegen and then somehow examined the KF7 markup, which could be used to write unit tests for all this. Frankly, I wouldn't mind except that extracting data from an old
.MOBI file seems super arcane. There ain't no JS library for that one, son.