From 9f7f74c952764957cd2b052c1eac2d06b4a01bfa Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Jan 2020 16:07:48 +0530 Subject: [PATCH] Comments editor: Use

 

for empty paragraphs instead --- src/calibre/gui2/comments_editor.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/comments_editor.py b/src/calibre/gui2/comments_editor.py index a7202dae90..7dcc909d6a 100644 --- a/src/calibre/gui2/comments_editor.py +++ b/src/calibre/gui2/comments_editor.py @@ -78,7 +78,7 @@ def lift_styles(tag, style_map): def filter_qt_styles(style): for k in tuple(style): # -qt-paragraph-type is a hack used by Qt for empty paragraphs - if k.startswith('-qt-') and k != '-qt-paragraph-type': + if k.startswith('-qt-'): del style[k] @@ -192,6 +192,9 @@ def cleanup_qt_markup(root): use_implicit_styling_for_a(child, style_map) for child in tag.iterdescendants('span'): use_implicit_styling_for_span(child, style_map[child]) + if tag.tag == 'p' and style_map[tag].get('-qt-paragraph-type') == 'empty': + del tag[:] + tag.text = '\xa0' for style in itervalues(style_map): filter_qt_styles(style) for tag, style in iteritems(style_map): @@ -1135,7 +1138,8 @@ class Editor(QWidget): # {{{ self.wyswyg_dirty = False elif index == 0: # changing to wyswyg if self.source_dirty: - self.editor.html = unicode_type(self.code_edit.toPlainText()) + from calibre.gui2.tweak_book.widgets import PlainTextEdit + self.editor.html = PlainTextEdit.toPlainText(self.code_edit) self.source_dirty = False @property @@ -1194,6 +1198,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.

\xa0

ss

' app.exec_() # print w.html