mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
DRYer
This commit is contained in:
parent
dedea474c8
commit
07b48787c9
@ -286,29 +286,29 @@ def unserialize_html(serialized_data, proceed, postprocess_dom, root_name):
|
|||||||
proceeded = True
|
proceeded = True
|
||||||
proceed()
|
proceed()
|
||||||
|
|
||||||
|
def process_children(node, parent):
|
||||||
|
if not node.c:
|
||||||
|
return
|
||||||
|
stack = v'[]'
|
||||||
|
for v'var i = node.c.length; i-- > 0;': # noqa: unused-local
|
||||||
|
child = v'node.c[i]'
|
||||||
|
if child.n is not 'meta' and child.n is not 'base':
|
||||||
|
stack.push(v'[child, parent]')
|
||||||
|
process_stack(stack, None, ns_map, load_required, onload)
|
||||||
|
|
||||||
|
|
||||||
body_done = False
|
body_done = False
|
||||||
process_stack.tag_id = 1
|
process_stack.tag_id = 1
|
||||||
for child in html.c:
|
for child in html.c:
|
||||||
if child.n is 'head':
|
if child.n is 'head':
|
||||||
if child.c:
|
process_children(child, document.head)
|
||||||
stack = v'[]'
|
|
||||||
for v'var i = child.c.length; i-- > 0;':
|
|
||||||
if child.c[i].n is not 'meta' and child.c[i].n is not 'base':
|
|
||||||
stack.push(v'[child.c[i], document.head]')
|
|
||||||
process_stack(stack, None, ns_map, load_required, onload)
|
|
||||||
elif child.n is 'body':
|
elif child.n is 'body':
|
||||||
if not body_done:
|
if not body_done:
|
||||||
body_done = True
|
body_done = True
|
||||||
apply_attributes(child, document.body, ns_map)
|
apply_attributes(child, document.body, ns_map)
|
||||||
if child.x:
|
if child.x:
|
||||||
document.body.appendChild(document.createTextNode(child.x))
|
document.body.appendChild(document.createTextNode(child.x))
|
||||||
if child.c:
|
process_children(child, document.body)
|
||||||
stack = v'[]'
|
|
||||||
for v'var i = child.c.length; i-- > 0;':
|
|
||||||
if child.c[i].n is not 'meta' and child.c[i].n is not 'base':
|
|
||||||
stack.push(v'[child.c[i], document.body]')
|
|
||||||
process_stack(stack, None, ns_map, load_required, onload)
|
|
||||||
|
|
||||||
if postprocess_dom:
|
if postprocess_dom:
|
||||||
postprocess_dom()
|
postprocess_dom()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user