mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -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)
|
||||
cssname = os.path.splitext(basename)[0] + '.css'
|
||||
stylesheets = [html_css_stylesheet()]
|
||||
head = xpath(tree, '/h:html/h:head')
|
||||
if head:
|
||||
head = head[0]
|
||||
else:
|
||||
head = []
|
||||
style_tags = xpath(tree, '//*[local-name()="style" or local-name()="link"]')
|
||||
|
||||
# Add cssutils parsing profiles from output_profile
|
||||
for profile in self.opts.output_profile.extra_css_modules:
|
||||
@ -187,7 +183,7 @@ class Stylizer(object):
|
||||
parser = CSSParser(fetcher=self._fetch_css_file,
|
||||
log=logging.getLogger('calibre.css'))
|
||||
self.font_face_rules = []
|
||||
for elem in head:
|
||||
for elem in style_tags:
|
||||
if (elem.tag == XHTML('style') and
|
||||
elem.get('type', CSS_MIME) in OEB_STYLES):
|
||||
text = elem.text if elem.text else u''
|
||||
|
@ -503,14 +503,14 @@ class CSSFlattener(object):
|
||||
def flatten_head(self, item, href, global_href):
|
||||
html = item.data
|
||||
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') \
|
||||
and node.get('rel', 'stylesheet') == 'stylesheet' \
|
||||
and node.get('type', CSS_MIME) in OEB_STYLES:
|
||||
head.remove(node)
|
||||
node.getparent().remove(node)
|
||||
elif node.tag == XHTML('style') \
|
||||
and node.get('type', CSS_MIME) in OEB_STYLES:
|
||||
head.remove(node)
|
||||
node.getparent().remove(node)
|
||||
href = item.relhref(href)
|
||||
l = etree.SubElement(head, XHTML('link'),
|
||||
rel='stylesheet', type=CSS_MIME, href=href)
|
||||
|
Loading…
x
Reference in New Issue
Block a user