From 12485fef82aa4209cb387ba75199d20e8aa9565e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 14 Oct 2019 15:46:46 +0530 Subject: [PATCH] Viewer: Fix error while viewing books with a comment after a tag. Fixes #1847977 [strange problem with epub in viewer 4](https://bugs.launchpad.net/calibre/+bug/1847977) --- src/calibre/srv/render_book.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/calibre/srv/render_book.py b/src/calibre/srv/render_book.py index f44eb5d458..c239dcc885 100644 --- a/src/calibre/srv/render_book.py +++ b/src/calibre/srv/render_book.py @@ -613,7 +613,8 @@ def html_as_dict(root): tail = getattr(child, 'tail', None) if tail: if prev_child_node is None: - parent_node = tags[node[-1]] + parent_node = node[-1] + parent_node = tags[parent_node] parent_node['x'] = parent_node.get('x', '') + tail else: prev_child_node['l'] = prev_child_node.get('l', '') + tail @@ -624,7 +625,7 @@ def html_as_dict(root): child_tree_node = [len(tags)-1] node.append(child_tree_node) stack.append((child, child_tree_node)) - prev_child_node = cnode + 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}