View Single Post
Old 08-19-2015, 02:01 AM   #39
dgatwood
Curmudgeon
dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.
 
dgatwood's Avatar
 
Posts: 629
Karma: 1623086
Join Date: Jan 2012
Device: iPad, iPhone, Nook Simple Touch
Quote:
Originally Posted by mattmc View Post
Okay, now there's the question of #2 and #3. You basically mention elements that have multiple classes, but I think for a truly universal solution a more complex approach is required. Correct me if I'm wrong, but it's not so much elements with multiple classes as it is elements that multiple selectors apply to, right?
I don't think so. Kindlegen seems to handle multiple matches correctly, with the last one taking precedence. The only multiple match issue I remember was when an element had multiple class names (class="foo bar").


Quote:
Originally Posted by mattmc View Post
Like, what if you have span.blah and you have a <p class="blah"> for whatever reason? The selector wouldn't actually apply in that scenario, but if you were just looking at classes, you would think it did.
I'm pretty sure that span.blah and p.blah are correctly treated as distinct.


Quote:
Originally Posted by mattmc View Post
Or if you have selectors #super and .duper, and element <p class="duper" id="super"> then both rules would apply to that element.
My recollection is that multiple rules matching a single element don't cause problems.


Quote:
Originally Posted by mattmc View Post
It's really all dependent on what kind of CSS is being used by the book creator; if you're just using classes then obviously that's fine, I'm just thinking it all the way through to the conclusion.

I suppose if you already got rid of all of the complex selectors, basically anything matching /[+~\[\] ]/, then all you have to worry about is IDs and classes? So you could walk the DOM with that in mind, I suppose.
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.
dgatwood is offline   Reply With Quote