mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Properly remove all attributes when unserializing HTML from the existin
HTML, HEAD and BODY tags
This commit is contained in:
parent
dc887b9780
commit
782c088bb9
@ -59,12 +59,21 @@ def build_rule(selector, **kw):
|
|||||||
ans.push('}')
|
ans.push('}')
|
||||||
return ans.join('\n') + '\n'
|
return ans.join('\n') + '\n'
|
||||||
|
|
||||||
|
|
||||||
def clear():
|
def clear():
|
||||||
for v'var i = 0; i < arguments.length; i++':
|
for v'var i = 0; i < arguments.length; i++':
|
||||||
node = arguments[i]
|
node = arguments[i]
|
||||||
while node.firstChild:
|
while node.firstChild:
|
||||||
node.removeChild(node.firstChild)
|
node.removeChild(node.firstChild)
|
||||||
|
|
||||||
|
|
||||||
|
def remove_all_attributes():
|
||||||
|
for v'var i = 0; i < arguments.length; i++':
|
||||||
|
node = arguments[i]
|
||||||
|
while node.attributes.length > 0:
|
||||||
|
node.removeAttribute(node.attributes[0].name)
|
||||||
|
|
||||||
|
|
||||||
def create_keyframes(animation_name, *frames):
|
def create_keyframes(animation_name, *frames):
|
||||||
ans = v'[]'
|
ans = v'[]'
|
||||||
for prefix in '-webkit-', '-moz-', '-o-', '':
|
for prefix in '-webkit-', '-moz-', '-o-', '':
|
||||||
|
@ -5,7 +5,7 @@ from __python__ import hash_literals
|
|||||||
from elementmaker import E
|
from elementmaker import E
|
||||||
from encodings import base64decode, utf8_decode
|
from encodings import base64decode, utf8_decode
|
||||||
|
|
||||||
from dom import clear
|
from dom import clear, remove_all_attributes
|
||||||
from read_book.globals import ui_operations
|
from read_book.globals import ui_operations
|
||||||
|
|
||||||
JSON_XHTML_MIMETYPE = 'application/calibre+xhtml+json'
|
JSON_XHTML_MIMETYPE = 'application/calibre+xhtml+json'
|
||||||
@ -228,9 +228,11 @@ def unserialize_html(serialized_data, proceed, postprocess_dom):
|
|||||||
tree = serialized_data.tree
|
tree = serialized_data.tree
|
||||||
ns_map = serialized_data.ns_map
|
ns_map = serialized_data.ns_map
|
||||||
html = tag_map[0]
|
html = tag_map[0]
|
||||||
|
remove_all_attributes(document.documentElement)
|
||||||
apply_attributes(html, document.documentElement, ns_map)
|
apply_attributes(html, document.documentElement, ns_map)
|
||||||
head, body = tree[1], tree[2] # noqa: unused-local
|
head, body = tree[1], tree[2] # noqa: unused-local
|
||||||
clear(document.head, document.body)
|
clear(document.head, document.body)
|
||||||
|
remove_all_attributes(document.head, document.body)
|
||||||
# Default stylesheet
|
# Default stylesheet
|
||||||
document.head.appendChild(E.style(type='text/css', 'html {{ font-family: {} }}'.format(window.default_font_family or "sans-serif")))
|
document.head.appendChild(E.style(type='text/css', 'html {{ font-family: {} }}'.format(window.default_font_family or "sans-serif")))
|
||||||
resource_urls = {}
|
resource_urls = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user