From 07b48787c9228d75af81bd93fc92008a9ccf6f3c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 3 Nov 2019 12:16:01 +0530 Subject: [PATCH] DRYer --- src/pyj/read_book/resources.pyj | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pyj/read_book/resources.pyj b/src/pyj/read_book/resources.pyj index afce0a48a5..fea033e91c 100644 --- a/src/pyj/read_book/resources.pyj +++ b/src/pyj/read_book/resources.pyj @@ -286,29 +286,29 @@ def unserialize_html(serialized_data, proceed, postprocess_dom, root_name): proceeded = True 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 process_stack.tag_id = 1 for child in html.c: if child.n is 'head': - if child.c: - 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) + process_children(child, document.head) elif child.n is 'body': if not body_done: body_done = True apply_attributes(child, document.body, ns_map) if child.x: document.body.appendChild(document.createTextNode(child.x)) - if child.c: - 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) + process_children(child, document.body) if postprocess_dom: postprocess_dom()