diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index a85c77fad4..b25e880f58 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -351,7 +351,7 @@ OEB_IMAGES = {GIF_MIME, JPEG_MIME, PNG_MIME, SVG_MIME} MS_COVER_TYPE = 'other.ms-coverimage-standard' -ENTITY_RE = re.compile(r'&([a-zA-Z_:][a-zA-Z0-9.-_:]+);') +ENTITY_RE = re.compile(r'&([a-zA-Z_:][a-zA-Z0-9._:-]+);') COLLAPSE_RE = re.compile(r'[ \t\r\n\v]+') QNAME_RE = re.compile(r'^[{][^{}]+[}][^{}]+$') PREFIXNAME_RE = re.compile(r'^[^:]+[:][^:]+') diff --git a/src/calibre/gui2/markdown_syntax_highlighter.py b/src/calibre/gui2/markdown_syntax_highlighter.py index 353a36eb1d..3d3c88f869 100644 --- a/src/calibre/gui2/markdown_syntax_highlighter.py +++ b/src/calibre/gui2/markdown_syntax_highlighter.py @@ -6,6 +6,7 @@ import re from qt.core import QApplication, QBrush, QColor, QFont, QSyntaxHighlighter, QTextCharFormat, QTextCursor, QTextLayout +from calibre.ebooks.oeb.base import ENTITY_RE from calibre.gui2.palette import dark_link_color, light_link_color @@ -31,7 +32,7 @@ class MarkdownHighlighter(QSyntaxHighlighter): 'HeaderLine': re.compile(r'(?u)^(-|=)+\s*$'), 'HR': re.compile(r'(?u)^(\s*(\*|-|_)\s*){3,}$'), 'Html': re.compile(r'(?u)'), - 'Entity': re.compile(r'&([A-z]{2,7}|#\d{1,7}|#x[\dA-Fa-f]{1,6});'), + 'Entity': ENTITY_RE, } key_theme_maps = { diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index feb2de578b..7ced4feadd 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -823,12 +823,11 @@ class TextEdit(PlainTextEdit): return self.text_for_range(c.block(), r) def select_class_name_at_cursor(self, cursor): - valid = re.compile(r'[\w_0-9\-]+', flags=re.UNICODE) + valid = re.compile(r'^[\w_-]+$', flags=re.UNICODE) def keep_going(): q = cursor.selectedText() - m = valid.match(q) - return m is not None and m.group() == q + return valid.match(q) is not None def run_loop(forward=True): cursor.setPosition(pos)