From 04d58d6877c441e2b1c1835ede1b35eee17ad7d0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 2 Jul 2019 17:59:15 +0530 Subject: [PATCH] Implement insertion of
--- src/calibre/gui2/comments_editor.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/comments_editor.py b/src/calibre/gui2/comments_editor.py index 77b2cb2508..22ce6184f0 100644 --- a/src/calibre/gui2/comments_editor.py +++ b/src/calibre/gui2/comments_editor.py @@ -28,6 +28,8 @@ from calibre.utils.imghdr import what from polyglot.builtins import filter, iteritems, itervalues, unicode_type +# Cleanup Qt markup {{{ + def parse_style(style): props = filter(None, (x.strip() for x in style.split(';'))) ans = {} @@ -129,7 +131,7 @@ def cleanup_qt_markup(root): tag_style = style_map[tag] remove_margins(tag, tag_style) remove_zero_indents(tag_style) - if tag.tag.startswith('h'): + if tag.tag.startswith('h') and tag.tag[1:] in '123456': remove_heading_font_styles(tag, tag_style) for child in tag.iterdescendants('span'): use_implicit_styling_for_span(child, style_map[child]) @@ -142,6 +144,7 @@ def cleanup_qt_markup(root): tag.attrib.pop('style', None) for span in root.xpath('//span[not(@style)]'): lift(span) +# }}} class EditorWidget(QTextEdit, LineEditECM): # {{{ @@ -456,7 +459,13 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{ self.setTextCursor(c) def do_insert_hr(self, *args): - raise NotImplementedError('TODO') + c = self.textCursor() + c.beginEditBlock() + c.movePosition(c.EndOfBlock, c.MoveAnchor) + c.insertHtml('
') + c.endEditBlock() + self.setTextCursor(c) + self.focus_self() def do_insert_link(self, *args): link, name, is_image = self.ask_link() @@ -652,6 +661,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{ # }}} + # Highlighter {{{