diff --git a/src/calibre/gui2/comments_editor.py b/src/calibre/gui2/comments_editor.py index 4881f5c43c..74a718bf4f 100644 --- a/src/calibre/gui2/comments_editor.py +++ b/src/calibre/gui2/comments_editor.py @@ -164,6 +164,16 @@ def merge_contiguous_links(root): n.getparent().remove(n) +def convert_anchors_to_ids(root): + anchors = root.xpath('//a[@name]') + for a in anchors: + p = a.getparent() + if len(a.attrib) == 1 and not p.text and a is p[0] and not a.text and not p.get('id') and a.get('name') and len(a) == 0: + p.text = a.tail + p.set('id', a.get('name')) + p.remove(a) + + def cleanup_qt_markup(root): from calibre.ebooks.docx.cleanup import lift style_map = defaultdict(dict) @@ -192,6 +202,7 @@ def cleanup_qt_markup(root): lift(span) merge_contiguous_links(root) + convert_anchors_to_ids(root) # }}} @@ -1179,6 +1190,6 @@ if __name__ == '__main__': w.html = '''
Test blockquote
He hadn't
set out to have an affair,
much less a long-term, devoted one.
hello''' - w.html = '
Testing a link.
Testing a link.