diff --git a/src/calibre/gui2/comments_editor.py b/src/calibre/gui2/comments_editor.py
index 094a65895e..4593957d03 100644
--- a/src/calibre/gui2/comments_editor.py
+++ b/src/calibre/gui2/comments_editor.py
@@ -225,6 +225,42 @@ def cleanup_qt_markup(root):
# }}}
+def fix_html(original_html, original_txt):
+ 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 not original_txt and ' 1:
+ ans = '
%s
'%ans + return xml_replace_entities(ans) + class EditorWidget(QTextEdit, LineEditECM): # {{{ data_changed = pyqtSignal() @@ -261,7 +297,6 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{ self.em_size = f.horizontalAdvance('m') self.base_url = None self._parent = weakref.ref(parent) - self.comments_pat = re.compile(r'', re.DOTALL) self.shortcut_map = {} def r(name, icon, text, checkable=False, shortcut=None): @@ -736,40 +771,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{ @property def html(self): - raw = original_html = self.toHtml() - check = self.toPlainText().strip() - raw = xml_to_unicode(raw, strip_encoding_pats=True, resolve_entities=True)[0] - raw = self.comments_pat.sub('', raw) - if not check and '%s
'%ans - return xml_replace_entities(ans) + return fix_html(self.toHtml(), self.toPlainText().strip()) @html.setter def html(self, val): @@ -822,6 +824,12 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{ c = self.textCursor() return c.hasSelection() + def createMimeDataFromSelection(self): + ans = super().createMimeDataFromSelection() + html, txt = ans.html(), ans.text() + ans.setHtml(fix_html(html, txt)) + return ans + def contextMenuEvent(self, ev): menu = QMenu(self) for ac in 'undo redo -- cut copy paste paste_and_match_style -- select_all'.split():