Viewer: Fix text after comments not being rendered. Fixes #1846875 [text after HTML comment in epub is not displayed](https://bugs.launchpad.net/calibre/+bug/1846875)

This commit is contained in:
Kovid Goyal 2019-10-06 07:21:40 +05:30
parent 94ea7c67ef
commit 5e25ebd6f1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -590,13 +590,25 @@ def html_as_dict(root):
stack = [(root, tree)]
while stack:
elem, node = stack.pop()
for child in elem.iterchildren('*'):
cnode = serialize_elem(child, nsmap)
if cnode is not None:
tags.append(cnode)
child_tree_node = [len(tags)-1]
node.append(child_tree_node)
stack.append((child, child_tree_node))
prev_child_node = None
for child in elem.iterchildren():
tag = getattr(child, 'tag', None)
if tag is None or callable(tag):
tail = getattr(child, 'tail', None)
if tail:
if prev_child_node is None:
parent_node = tags[node[-1]]
parent_node['x'] = parent_node.get('x', '') + tail
else:
prev_child_node['l'] = prev_child_node.get('l', '') + tail
else:
cnode = serialize_elem(child, nsmap)
if cnode is not None:
tags.append(cnode)
child_tree_node = [len(tags)-1]
node.append(child_tree_node)
stack.append((child, child_tree_node))
prev_child_node = cnode
ns_map = [ns for ns, nsnum in sorted(iteritems(nsmap), key=lambda x: x[1])]
return {'ns_map':ns_map, 'tag_map':tags, 'tree':tree}