From 7ca2f68e5392a399f7673a5418609e6a145f2548 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 4 Oct 2019 15:42:25 +0530 Subject: [PATCH] Comments editor: Workaround for Qt converting ids into anchors --- src/calibre/gui2/comments_editor.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 Heading

Test blockquote

He hadn't set out to have an affair, much less a long-term, devoted one.

hello''' - w.html = '

Testing a link.

' + w.html = '

Testing a link.

' app.exec_() # print w.html