Edit Book: Fix newlines not being matched by the "Search ignoring markup" tool. Fixes #1649383 [Search ignoring HTML markup in book editor ignores "Dot all"](https://bugs.launchpad.net/calibre/+bug/1649383)

This commit is contained in:
Kovid Goyal 2016-12-13 18:06:32 +05:30
parent e1a0e184c7
commit 6d2d835265

View File

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