Comments editor: Use <p>&nbsp;</p> for empty paragraphs instead

This commit is contained in:
Kovid Goyal 2020-01-16 16:07:48 +05:30
parent 3236f5da9e
commit 9f7f74c952
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -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 = '''<h1>Test Heading</h1><blockquote>Test blockquote</blockquote><p><span style="background-color: rgb(0, 255, 255); ">He hadn't
set <u>out</u> to have an <em>affair</em>, <span style="font-style:italic; background-color:red">
much</span> less a <s>long-term</s>, <b>devoted</b> one.</span><p>hello'''
w.html = '<div><p id="moo">Testing <em>a</em> link.</p></div>'
w.html = '<div><p id="moo">Testing <em>a</em> link.</p><p>\xa0</p><p>ss</p></div>'
app.exec_()
# print w.html