diff --git a/src/calibre/gui2/markdown_syntax_highlighter.py b/src/calibre/gui2/markdown_syntax_highlighter.py index adb280a7e4..5bb0c5d10a 100644 --- a/src/calibre/gui2/markdown_syntax_highlighter.py +++ b/src/calibre/gui2/markdown_syntax_highlighter.py @@ -20,19 +20,19 @@ class MarkdownHighlighter(QSyntaxHighlighter): 'uBold': re.compile(r'(?__)(?P.+?)(?P=delim)'), 'uItalic': re.compile(r'(?_)(?!_)(?P([^_]{2,}?|[^_]))(?___)(?P([^_]{2,}?|[^_]))(?+[ \t]?'), + 'Link': re.compile(r'(?+[ \t]?'), + 'CodeBlock': re.compile('^([ ]{4,}|[ ]*\t).*'), 'CodeSpan': re.compile(r'(?`+).+?(?P=delim)'), 'HeaderLine': re.compile(r'(?u)^(-|=)+\s*$'), 'HR': re.compile(r'(?u)^(\s*(\*|-|_)\s*){3,}$'), - 'Html': re.compile(r'<.+?(?') + 'Html': re.compile(r'(?u)') } key_theme_maps = { @@ -147,7 +147,7 @@ class MarkdownHighlighter(QSyntaxHighlighter): def highlightBlockQuote(self, text, cursor, bf): found = False - mo = re.search(self.MARKDOWN_KEYS_REGEX['BlockQuote'],text) + mo = re.match(self.MARKDOWN_KEYS_REGEX['BlockQuote'],text) if mo: self.setFormat(self.offset+ mo.start(), mo.end() - mo.start(), self.MARKDOWN_KWS_FORMAT['BlockQuote']) self.offset += mo.end() @@ -290,7 +290,7 @@ class MarkdownHighlighter(QSyntaxHighlighter): found = False for mo in re.finditer(self.MARKDOWN_KEYS_REGEX['CodeBlock'],text): stripped = text.lstrip() - if stripped[0] not in ('*','-','+','>') and not re.match(r'\d+\.', stripped): + if stripped[0] not in ('*','-','+') and not re.match(self.MARKDOWN_KEYS_REGEX['OrderedList'], stripped): self.setFormat(self.offset+ mo.start(), mo.end() - mo.start(), self.MARKDOWN_KWS_FORMAT['CodeBlock']) found = True return found