diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index c2b404ca49..04733e021a 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -303,7 +303,7 @@ def rewrite_links(root, link_repl_func, resolve_base_href=False): except UnicodeDecodeError: 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 el.text): stylesheet = parser.parseString(el.text, validate=False) diff --git a/src/calibre/ebooks/oeb/polish/cascade.py b/src/calibre/ebooks/oeb/polish/cascade.py index c6b6bc97d0..fb163e24f4 100644 --- a/src/calibre/ebooks/oeb/polish/cascade.py +++ b/src/calibre/ebooks/oeb/polish/cascade.py @@ -14,7 +14,7 @@ from tinycss.fonts3 import parse_font_family, serialize_font_family from calibre import as_unicode 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.stylizer import INHERITED, media_ok 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') - 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 not elem.text: continue diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index ff8178ab79..fdb5e44195 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -24,7 +24,7 @@ from tinycss.media3 import CSSMedia3Parser from calibre import as_unicode, force_unicode 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.utils.resources import get_path as P from polyglot.builtins import iteritems @@ -247,7 +247,7 @@ class Stylizer: parser = CSSParser(fetcher=self._fetch_css_file, log=logging.getLogger('calibre.css')) 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 '' for x in elem: t = getattr(x, 'text', None) diff --git a/src/calibre/ebooks/oeb/transforms/flatcss.py b/src/calibre/ebooks/oeb/transforms/flatcss.py index 214e06e55a..fae357e8d3 100644 --- a/src/calibre/ebooks/oeb/transforms/flatcss.py +++ b/src/calibre/ebooks/oeb/transforms/flatcss.py @@ -19,7 +19,7 @@ from lxml import etree from calibre import guess_type 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.utils.filenames import ascii_filename, ascii_text 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('type', CSS_MIME)) in OEB_STYLES: 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: node.getparent().remove(node) href = item.relhref(href)