From c8c3741d342cd644781137bc26811f08e1efcb0d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 3 Jul 2013 13:36:30 +0530 Subject: [PATCH] DOCX: Handle redundant bookmarks DOCX Input: Fix links pointing to locations in the same document that contain multiple, redundant bookmarks not working. --- src/calibre/ebooks/docx/to_html.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/calibre/ebooks/docx/to_html.py b/src/calibre/ebooks/docx/to_html.py index 26e50f9b9d..01808657ea 100644 --- a/src/calibre/ebooks/docx/to_html.py +++ b/src/calibre/ebooks/docx/to_html.py @@ -342,7 +342,13 @@ class Convert(object): elif x.tag.endswith('}bookmarkStart'): anchor = get(x, 'w:name') if anchor and anchor not in self.anchor_map: + old_anchor = current_anchor self.anchor_map[anchor] = current_anchor = generate_anchor(anchor, frozenset(self.anchor_map.itervalues())) + if old_anchor is not None: + # The previous anchor was not applied to any element + for a, t in tuple(self.anchor_map.iteritems()): + if t == old_anchor: + self.anchor_map[a] = current_anchor elif x.tag.endswith('}hyperlink'): current_hyperlink = x