DOCX Input: Fix a bookmark at the end of a paragraph causing the bookmark at the start of the paragraph to be skipped. Fixes #1942805 [Private bug](https://bugs.launchpad.net/calibre/+bug/1942805)

This commit is contained in:
Kovid Goyal 2021-09-07 14:25:45 +05:30
parent 44bf6e3859
commit 94dbd026d0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -473,7 +473,7 @@ class Convert(object):
self.anchor_map[anchor] = current_anchor = generate_anchor(anchor, frozenset(itervalues(self.anchor_map))) self.anchor_map[anchor] = current_anchor = generate_anchor(anchor, frozenset(itervalues(self.anchor_map)))
if old_anchor is not None: if old_anchor is not None:
# The previous anchor was not applied to any element # The previous anchor was not applied to any element
for a, t in tuple(iteritems(self.anchor_map)): for a, t in tuple(self.anchor_map.items()):
if t == old_anchor: if t == old_anchor:
self.anchor_map[a] = current_anchor self.anchor_map[a] = current_anchor
elif x.tag.endswith('}hyperlink'): elif x.tag.endswith('}hyperlink'):
@ -489,8 +489,18 @@ class Convert(object):
if t == old_anchor: if t == old_anchor:
self.anchor_map[a] = current_anchor self.anchor_map[a] = current_anchor
if current_anchor is not None: if current_anchor is not None:
# This paragraph had no <w:r> descendants if dest.get('id'):
dest.set('id', current_anchor) # this bookmark was at the end of the paragraph
if len(dest):
if dest[-1].get('id'):
self.anchor_map[current_anchor] = dest[-1].get('id')
else:
dest[-1].set('id', current_anchor)
else:
self.anchor_map[current_anchor] = dest.get('id')
else:
# This paragraph had no <w:r> descendants
dest.set('id', current_anchor)
current_anchor = None current_anchor = None
m = re.match(r'heading\s+(\d+)$', style.style_name or '', re.IGNORECASE) m = re.match(r'heading\s+(\d+)$', style.style_name or '', re.IGNORECASE)