mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Accurately namespace in-head stylesheets. Be stricter with element matching rules.
This commit is contained in:
parent
a52c0b5c21
commit
156d923b8c
@ -20,7 +20,7 @@ import cssutils
|
|||||||
from cssutils.css import CSSStyleRule, CSSPageRule, CSSStyleDeclaration, \
|
from cssutils.css import CSSStyleRule, CSSPageRule, CSSStyleDeclaration, \
|
||||||
CSSValueList, cssproperties
|
CSSValueList, cssproperties
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from calibre.ebooks.lit.oeb import XHTML_NS, CSS_MIME, OEB_STYLES
|
from calibre.ebooks.lit.oeb import XHTML, XHTML_NS, CSS_MIME, OEB_STYLES
|
||||||
from calibre.ebooks.lit.oeb import barename, urlnormalize
|
from calibre.ebooks.lit.oeb import barename, urlnormalize
|
||||||
from calibre.resources import html_css
|
from calibre.resources import html_css
|
||||||
|
|
||||||
@ -126,12 +126,12 @@ class Stylizer(object):
|
|||||||
parser = cssutils.CSSParser()
|
parser = cssutils.CSSParser()
|
||||||
parser.setFetcher(lambda path: ('utf-8', oeb.container.read(path)))
|
parser.setFetcher(lambda path: ('utf-8', oeb.container.read(path)))
|
||||||
for elem in head:
|
for elem in head:
|
||||||
tag = barename(elem.tag)
|
if elem.tag == XHTML('style') and elem.text \
|
||||||
if tag == 'style':
|
and elem.get('type', CSS_MIME) in OEB_STYLES:
|
||||||
text = ''.join(elem.text)
|
text = XHTML_CSS_NAMESPACE + elem.text
|
||||||
stylesheet = parser.parseString(text, href=cssname)
|
stylesheet = parser.parseString(text, href=cssname)
|
||||||
stylesheets.append(stylesheet)
|
stylesheets.append(stylesheet)
|
||||||
elif tag == 'link' \
|
elif elem.tag == XHTML('link') and elem.get('href') \
|
||||||
and elem.get('rel', 'stylesheet') == 'stylesheet' \
|
and elem.get('rel', 'stylesheet') == 'stylesheet' \
|
||||||
and elem.get('type', CSS_MIME) in OEB_STYLES:
|
and elem.get('type', CSS_MIME) in OEB_STYLES:
|
||||||
href = urlnormalize(elem.attrib['href'])
|
href = urlnormalize(elem.attrib['href'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user