mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Conversion: Add support for <style> and <link> tags outside the <head> tag. Fixes #1274339 [incorrect class substitution in html](https://bugs.launchpad.net/calibre/+bug/1274339)
This commit is contained in:
parent
5eb1745526
commit
ec38ff9b95
@ -172,11 +172,7 @@ class Stylizer(object):
|
|||||||
basename = os.path.basename(path)
|
basename = os.path.basename(path)
|
||||||
cssname = os.path.splitext(basename)[0] + '.css'
|
cssname = os.path.splitext(basename)[0] + '.css'
|
||||||
stylesheets = [html_css_stylesheet()]
|
stylesheets = [html_css_stylesheet()]
|
||||||
head = xpath(tree, '/h:html/h:head')
|
style_tags = xpath(tree, '//*[local-name()="style" or local-name()="link"]')
|
||||||
if head:
|
|
||||||
head = head[0]
|
|
||||||
else:
|
|
||||||
head = []
|
|
||||||
|
|
||||||
# Add cssutils parsing profiles from output_profile
|
# Add cssutils parsing profiles from output_profile
|
||||||
for profile in self.opts.output_profile.extra_css_modules:
|
for profile in self.opts.output_profile.extra_css_modules:
|
||||||
@ -187,7 +183,7 @@ class Stylizer(object):
|
|||||||
parser = CSSParser(fetcher=self._fetch_css_file,
|
parser = CSSParser(fetcher=self._fetch_css_file,
|
||||||
log=logging.getLogger('calibre.css'))
|
log=logging.getLogger('calibre.css'))
|
||||||
self.font_face_rules = []
|
self.font_face_rules = []
|
||||||
for elem in head:
|
for elem in style_tags:
|
||||||
if (elem.tag == XHTML('style') and
|
if (elem.tag == XHTML('style') and
|
||||||
elem.get('type', CSS_MIME) in OEB_STYLES):
|
elem.get('type', CSS_MIME) in OEB_STYLES):
|
||||||
text = elem.text if elem.text else u''
|
text = elem.text if elem.text else u''
|
||||||
|
@ -503,14 +503,14 @@ class CSSFlattener(object):
|
|||||||
def flatten_head(self, item, href, global_href):
|
def flatten_head(self, item, href, global_href):
|
||||||
html = item.data
|
html = item.data
|
||||||
head = html.find(XHTML('head'))
|
head = html.find(XHTML('head'))
|
||||||
for node in head:
|
for node in html.xpath('//*[local-name()="style" or local-name()="link"]'):
|
||||||
if node.tag == XHTML('link') \
|
if node.tag == XHTML('link') \
|
||||||
and node.get('rel', 'stylesheet') == 'stylesheet' \
|
and node.get('rel', 'stylesheet') == 'stylesheet' \
|
||||||
and node.get('type', CSS_MIME) in OEB_STYLES:
|
and node.get('type', CSS_MIME) in OEB_STYLES:
|
||||||
head.remove(node)
|
node.getparent().remove(node)
|
||||||
elif node.tag == XHTML('style') \
|
elif node.tag == XHTML('style') \
|
||||||
and node.get('type', CSS_MIME) in OEB_STYLES:
|
and node.get('type', CSS_MIME) in OEB_STYLES:
|
||||||
head.remove(node)
|
node.getparent().remove(node)
|
||||||
href = item.relhref(href)
|
href = item.relhref(href)
|
||||||
l = etree.SubElement(head, XHTML('link'),
|
l = etree.SubElement(head, XHTML('link'),
|
||||||
rel='stylesheet', type=CSS_MIME, href=href)
|
rel='stylesheet', type=CSS_MIME, href=href)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user