mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Micro optimization
This commit is contained in:
parent
1b679ae5c8
commit
1668365156
@ -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 <meta> 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:
|
||||
|
@ -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,7 +201,8 @@ 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 src.a:
|
||||
for a in src.a:
|
||||
if a[0] is attr:
|
||||
loadable = a[1].startswith('blob:')
|
||||
resource_urls[a[1]] = True
|
||||
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user