← Back to team overview

calibre-devs team mailing list archive

CSS normalization

 

Hi Kovid etc:

Ticket #1654 has revealed a fairly deep bug in the way any2epub does CSS
normalization.  The basic scenario is that the source has CSS and markup
like this:

    p.prelims { text-align: left; }

    <p class="prelims" style="text-align: center">TOR</p>

Calibre is currently turning that into:

    p.prelims { text-align: left; }
    .calibre_class_6 { text-align: center; }

    <p class="prelims calibre_class_6">TOR</p>

In the original, the implicit rule provided by the 'style' property has
the highest specificity, and the text is centered.  In the generated
CSS+markup, the '.calibre_class_6' rule has a lower specificity than the
'p.prelims' rule, and the text ends up being left-aligned instead of
centered.

In the CSSFlattener transform I collapse all CSS rules into single-class
class selectors, which circumvents this problem.  It does deform the
original source CSS rules, but practically speaking I'm not sure the
number of generated rules any2epub presently creates serves the purpose
of producing human-legible CSS much better...

Probably not a hugely frequent problem, but definitely a bug.

-Marshall



Follow ups