diff --git a/src/calibre/gui2/tweak_book/editor/smarts/html.py b/src/calibre/gui2/tweak_book/editor/smarts/html.py index 819ebfcd55..b137193bba 100644 --- a/src/calibre/gui2/tweak_book/editor/smarts/html.py +++ b/src/calibre/gui2/tweak_book/editor/smarts/html.py @@ -250,6 +250,7 @@ def ensure_not_within_tag_definition(cursor, forward=True): return False + BLOCK_TAG_NAMES = frozenset(( 'address', 'article', 'aside', 'blockquote', 'center', 'dir', 'fieldset', 'isindex', 'menu', 'noframes', 'hgroup', 'noscript', 'pre', 'section', @@ -294,6 +295,7 @@ def set_style_property(tag, property_name, value, editor): d.setProperty(property_name, value) c.insertText('"%s"' % css(d)) + entity_pat = re.compile(r'&(#{0,1}[a-zA-Z0-9]{1,8});$') @@ -700,6 +702,7 @@ class Smarts(NullSmarts): in_text = find_tag_definition(block, 0)[0] is None def append(text, start): + text = text.replace(PARAGRAPH_SEPARATOR, '\n') after = start + len(text) if start <= cend and cstart < after: extra = after - (cend + 1) @@ -715,9 +718,8 @@ class Smarts(NullSmarts): if not boundaries: # Add the whole line if in_text: - text = block.text() - if text: - append(text, block.position()) + text = block.text() + '\n' + append(text, block.position()) else: start = block.position() c.setPosition(start) @@ -733,11 +735,12 @@ class Smarts(NullSmarts): c.setPosition(block.position() + boundaries[-1].offset + 1) c.movePosition(c.EndOfBlock, c.KeepAnchor) if c.hasSelection(): - append(c.selectedText(), c.anchor()) + append(c.selectedText() + '\n', c.anchor()) block = block.next() s, e = find_text_in_chunks(pat, chunks) return s != -1 and e != -1, s, e + if __name__ == '__main__': # {{{ from calibre.gui2.tweak_book.editor.widget import launch_editor if sys.argv[-1].endswith('.html'):