diff --git a/src/calibre/srv/render_book.py b/src/calibre/srv/render_book.py index c4a4466ff1..e9c30678d1 100644 --- a/src/calibre/srv/render_book.py +++ b/src/calibre/srv/render_book.py @@ -443,6 +443,9 @@ def map_epub_type(epub_type, attribs, elem): attribs[i] = ['role', role] +known_tags = ('img', 'script', 'link', 'image', 'style') + + def serialize_elem(elem, nsmap): ns, name = split_name(elem.tag) nl = name.lower() @@ -450,7 +453,7 @@ def serialize_elem(elem, nsmap): ns, name = None, 'epub-' + name if nl == 'meta': return # Filter out tags as they have unknown side-effects - if nl in {'img', 'script', 'link', 'image', 'style'}: + if nl in known_tags: name = nl ans = {'n':name} if elem.text: diff --git a/src/pyj/read_book/resources.pyj b/src/pyj/read_book/resources.pyj index efb35bf5d2..4c5ea4a14e 100644 --- a/src/pyj/read_book/resources.pyj +++ b/src/pyj/read_book/resources.pyj @@ -164,7 +164,7 @@ def finalize_resources(book, root_name, resource_data): return root_data, mathjax, blob_url_map -js_types = set('text/javascript text/ecmascript application/javascript application/ecmascript'.split(' ')) +js_types = {k: True for k in 'text/javascript text/ecmascript application/javascript application/ecmascript'.split(' ')} resource_tag_names = {'script':'src', 'link':'href', 'img':'src', 'image':'xlink:href'} ns_rmap = {'http://www.w3.org/2000/svg':'svg', 'http://www.w3.org/1999/xlink':'xlink', 'http://www.w3.org/1998/Math/MathML':'math', 'http://www.w3.org/XML/1998/namespace': 'xml'} ns_count = 0 @@ -201,11 +201,12 @@ def process_stack(stack, tag_map, ns_map, load_required, onload, resource_urls): if attr: if attr.indexOf(':') != -1: attr = attr.replace('xlink:', '') - for a in (src.a or v'[]'): - if a[0] is attr: - loadable = a[1].startswith('blob:') - resource_urls[a[1]] = True - break + if src.a: + for a in src.a: + if a[0] is attr: + loadable = a[1].startswith('blob:') + resource_urls[a[1]] = True + break if loadable: load_required.add(node[0]) elem.addEventListener('load', onload.bind(node[0])) @@ -214,7 +215,7 @@ def process_stack(stack, tag_map, ns_map, load_required, onload, resource_urls): apply_attributes(src, elem, ns_map) parent.appendChild(elem) if src.x: - if src.n is 'script' and (elem.getAttribute('type') or 'text/javascript').toLowerCase() in js_types: + if src.n is 'script' and js_types[(elem.getAttribute('type') or 'text/javascript').toLowerCase()] is True: elem.text = src.x else: elem.appendChild(document.createTextNode(src.x))