From 8e18a509cb7b0c5cbe1e0a4b657afe21289e42a2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 2 Apr 2023 12:59:05 +0530 Subject: [PATCH] A better fix for block properties not being copied in comments_editor Removing the fragment copies causes pasting of the HTML into another comment editor to insert a spurious block. Instead move the comment to before

when needed. --- src/calibre/gui2/comments_editor.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/comments_editor.py b/src/calibre/gui2/comments_editor.py index 4593957d03..71599805cf 100644 --- a/src/calibre/gui2/comments_editor.py +++ b/src/calibre/gui2/comments_editor.py @@ -225,11 +225,12 @@ def cleanup_qt_markup(root): # }}} -def fix_html(original_html, original_txt): +def fix_html(original_html, original_txt, remove_comments=True): raw = original_html raw = xml_to_unicode(raw, strip_encoding_pats=True, resolve_entities=True)[0] - comments_pat = re.compile(r'', re.DOTALL) - raw = comments_pat.sub('', raw) + if remove_comments: + comments_pat = re.compile(r'', re.DOTALL) + raw = comments_pat.sub('', raw) if not original_txt and ')()', r'\2\1', html, count=1) + ans.setHtml(html) return ans def contextMenuEvent(self, ev): @@ -1255,6 +1266,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.

\xa0

ss

' + w.html = '

Testing a link.

\xa0

ss

' app.exec() # print w.html