mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Conversion: Fix <style> tags inside <svg> tags not being processed
See #2058798 (unwanted changes of svg code during conversion)
This commit is contained in:
parent
b0e899d53c
commit
a227d5e3be
@ -303,7 +303,7 @@ def rewrite_links(root, link_repl_func, resolve_base_href=False):
|
|||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if tag == XHTML('style') and el.text and \
|
if tag in (XHTML('style'), SVG('style')) and el.text and \
|
||||||
(_css_url_re.search(el.text) is not None or '@import' in
|
(_css_url_re.search(el.text) is not None or '@import' in
|
||||||
el.text):
|
el.text):
|
||||||
stylesheet = parser.parseString(el.text, validate=False)
|
stylesheet = parser.parseString(el.text, validate=False)
|
||||||
|
@ -14,7 +14,7 @@ from tinycss.fonts3 import parse_font_family, serialize_font_family
|
|||||||
|
|
||||||
from calibre import as_unicode
|
from calibre import as_unicode
|
||||||
from calibre.ebooks.css_transform_rules import all_properties
|
from calibre.ebooks.css_transform_rules import all_properties
|
||||||
from calibre.ebooks.oeb.base import OEB_STYLES, XHTML, css_text
|
from calibre.ebooks.oeb.base import OEB_STYLES, SVG, XHTML, css_text
|
||||||
from calibre.ebooks.oeb.normalize_css import DEFAULTS, normalizers
|
from calibre.ebooks.oeb.normalize_css import DEFAULTS, normalizers
|
||||||
from calibre.ebooks.oeb.stylizer import INHERITED, media_ok
|
from calibre.ebooks.oeb.stylizer import INHERITED, media_ok
|
||||||
from calibre.utils.resources import get_path as P
|
from calibre.utils.resources import get_path as P
|
||||||
@ -187,7 +187,7 @@ def resolve_styles(container, name, select=None, sheet_callback=None):
|
|||||||
|
|
||||||
process_sheet(html_css_stylesheet(container), 'user-agent.css')
|
process_sheet(html_css_stylesheet(container), 'user-agent.css')
|
||||||
|
|
||||||
for elem in root.iterdescendants(XHTML('style'), XHTML('link')):
|
for elem in root.iterdescendants(XHTML('style'), SVG('style'), XHTML('link')):
|
||||||
if elem.tag.lower().endswith('style'):
|
if elem.tag.lower().endswith('style'):
|
||||||
if not elem.text:
|
if not elem.text:
|
||||||
continue
|
continue
|
||||||
|
@ -24,7 +24,7 @@ from tinycss.media3 import CSSMedia3Parser
|
|||||||
|
|
||||||
from calibre import as_unicode, force_unicode
|
from calibre import as_unicode, force_unicode
|
||||||
from calibre.ebooks import unit_convert
|
from calibre.ebooks import unit_convert
|
||||||
from calibre.ebooks.oeb.base import CSS_MIME, OEB_STYLES, XHTML, XHTML_NS, urlnormalize, xpath
|
from calibre.ebooks.oeb.base import CSS_MIME, OEB_STYLES, SVG, XHTML, XHTML_NS, urlnormalize, xpath
|
||||||
from calibre.ebooks.oeb.normalize_css import DEFAULTS, normalizers
|
from calibre.ebooks.oeb.normalize_css import DEFAULTS, normalizers
|
||||||
from calibre.utils.resources import get_path as P
|
from calibre.utils.resources import get_path as P
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
@ -247,7 +247,7 @@ class Stylizer:
|
|||||||
parser = CSSParser(fetcher=self._fetch_css_file,
|
parser = CSSParser(fetcher=self._fetch_css_file,
|
||||||
log=logging.getLogger('calibre.css'))
|
log=logging.getLogger('calibre.css'))
|
||||||
for elem in style_tags:
|
for elem in style_tags:
|
||||||
if (elem.tag == XHTML('style') and elem.get('type', CSS_MIME) in OEB_STYLES and media_ok(elem.get('media'))):
|
if (elem.tag in (XHTML('style'), SVG('style')) and elem.get('type', CSS_MIME) in OEB_STYLES and media_ok(elem.get('media'))):
|
||||||
text = elem.text if elem.text else ''
|
text = elem.text if elem.text else ''
|
||||||
for x in elem:
|
for x in elem:
|
||||||
t = getattr(x, 'text', None)
|
t = getattr(x, 'text', None)
|
||||||
|
@ -19,7 +19,7 @@ from lxml import etree
|
|||||||
|
|
||||||
from calibre import guess_type
|
from calibre import guess_type
|
||||||
from calibre.ebooks import unit_convert
|
from calibre.ebooks import unit_convert
|
||||||
from calibre.ebooks.oeb.base import CSS_MIME, OEB_STYLES, SVG_NS, XHTML, XHTML_NS, XPath, barename, css_text, namespace
|
from calibre.ebooks.oeb.base import CSS_MIME, OEB_STYLES, SVG, SVG_NS, XHTML, XHTML_NS, XPath, barename, css_text, namespace
|
||||||
from calibre.ebooks.oeb.stylizer import Stylizer
|
from calibre.ebooks.oeb.stylizer import Stylizer
|
||||||
from calibre.utils.filenames import ascii_filename, ascii_text
|
from calibre.utils.filenames import ascii_filename, ascii_text
|
||||||
from calibre.utils.icu import numeric_sort_key
|
from calibre.utils.icu import numeric_sort_key
|
||||||
@ -590,7 +590,7 @@ class CSSFlattener:
|
|||||||
and safe_lower(node.get('rel', 'stylesheet')) == 'stylesheet' \
|
and safe_lower(node.get('rel', 'stylesheet')) == 'stylesheet' \
|
||||||
and safe_lower(node.get('type', CSS_MIME)) in OEB_STYLES:
|
and safe_lower(node.get('type', CSS_MIME)) in OEB_STYLES:
|
||||||
node.getparent().remove(node)
|
node.getparent().remove(node)
|
||||||
elif node.tag == XHTML('style') \
|
elif node.tag in (XHTML('style'), SVG('style')) \
|
||||||
and node.get('type', CSS_MIME) in OEB_STYLES:
|
and node.get('type', CSS_MIME) in OEB_STYLES:
|
||||||
node.getparent().remove(node)
|
node.getparent().remove(node)
|
||||||
href = item.relhref(href)
|
href = item.relhref(href)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user