mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
regex tweaks
This commit is contained in:
parent
af2656c3b5
commit
4ff5af7576
@ -20,19 +20,19 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
|||||||
'uBold': re.compile(r'(?<!\\)(?P<delim>__)(?P<text>.+?)(?P=delim)'),
|
'uBold': re.compile(r'(?<!\\)(?P<delim>__)(?P<text>.+?)(?P=delim)'),
|
||||||
'uItalic': re.compile(r'(?<![_\\])(?P<delim>_)(?!_)(?P<text>([^_]{2,}?|[^_]))(?<![_\\])(?P=delim)'),
|
'uItalic': re.compile(r'(?<![_\\])(?P<delim>_)(?!_)(?P<text>([^_]{2,}?|[^_]))(?<![_\\])(?P=delim)'),
|
||||||
'uBoldItalic': re.compile(r'(?<!\\)(?P<delim>___)(?P<text>([^_]{2,}?|[^_]))(?<!\\)(?P=delim)'),
|
'uBoldItalic': re.compile(r'(?<!\\)(?P<delim>___)(?P<text>([^_]{2,}?|[^_]))(?<!\\)(?P=delim)'),
|
||||||
'Link': re.compile(r'(?u)(?<![!\\]])\[.*?(?<!\\)\](\[.+?(?<!\\)\]|\(.+?(?<!\\)\))'),
|
'Link': re.compile(r'(?<![!\\]])\[.*?(?<!\\)\](\[.+?(?<!\\)\]|\(.+?(?<!\\)\))'),
|
||||||
'Image': re.compile(r'(?u)(?<!\\)!\[.*?(?<!\\)\](\[.+?(?<!\\)\]|\(.+?(?<!\\)\))'),
|
'Image': re.compile(r'(?<!\\)!\[.*?(?<!\\)\](\[.+?(?<!\\)\]|\(.+?(?<!\\)\))'),
|
||||||
'LinkRef': re.compile(r'(?u)^ *\[.*?\]:[ \t]*.*$'),
|
'LinkRef': re.compile(r'^(?u)^\s*\[.*?\]:\s*[^\s].*'),
|
||||||
'Header': re.compile(r'(?u)^#{1,6}(.*?)$'),
|
'Header': re.compile(r'^#{1,6}.*'),
|
||||||
'CodeBlock': re.compile('^([ ]{4,}|\t).*'),
|
'UnorderedList': re.compile(r'(?u)^\s*(\*|\+|-)[ \t]\s*'),
|
||||||
'UnorderedList': re.compile(r'(?u)^\s*(\* |\+ |- )+\s*'),
|
'UnorderedListStar': re.compile(r'(?u)^\s*\*[ \t]\s*'),
|
||||||
'UnorderedListStar': re.compile(r'^\s*(\* )+\s*'),
|
'OrderedList': re.compile(r'(?u)^\s*\d+\.[ \t]\s*'),
|
||||||
'OrderedList': re.compile(r'(?u)^\s*(\d+\. )\s*'),
|
'BlockQuote': re.compile(r'^[ ]{0,3}>+[ \t]?'),
|
||||||
'BlockQuote': re.compile(r'(?u)^[ ]{0,3}>+[ \t]?'),
|
'CodeBlock': re.compile('^([ ]{4,}|[ ]*\t).*'),
|
||||||
'CodeSpan': re.compile(r'(?<!\\)(?P<delim>`+).+?(?P=delim)'),
|
'CodeSpan': re.compile(r'(?<!\\)(?P<delim>`+).+?(?P=delim)'),
|
||||||
'HeaderLine': re.compile(r'(?u)^(-|=)+\s*$'),
|
'HeaderLine': re.compile(r'(?u)^(-|=)+\s*$'),
|
||||||
'HR': re.compile(r'(?u)^(\s*(\*|-|_)\s*){3,}$'),
|
'HR': re.compile(r'(?u)^(\s*(\*|-|_)\s*){3,}$'),
|
||||||
'Html': re.compile(r'<.+?(?<!\\)>')
|
'Html': re.compile(r'(?u)</?[^/\s].*?(?<!\\)>')
|
||||||
}
|
}
|
||||||
|
|
||||||
key_theme_maps = {
|
key_theme_maps = {
|
||||||
@ -147,7 +147,7 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
|||||||
|
|
||||||
def highlightBlockQuote(self, text, cursor, bf):
|
def highlightBlockQuote(self, text, cursor, bf):
|
||||||
found = False
|
found = False
|
||||||
mo = re.search(self.MARKDOWN_KEYS_REGEX['BlockQuote'],text)
|
mo = re.match(self.MARKDOWN_KEYS_REGEX['BlockQuote'],text)
|
||||||
if mo:
|
if mo:
|
||||||
self.setFormat(self.offset+ mo.start(), mo.end() - mo.start(), self.MARKDOWN_KWS_FORMAT['BlockQuote'])
|
self.setFormat(self.offset+ mo.start(), mo.end() - mo.start(), self.MARKDOWN_KWS_FORMAT['BlockQuote'])
|
||||||
self.offset += mo.end()
|
self.offset += mo.end()
|
||||||
@ -290,7 +290,7 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
|||||||
found = False
|
found = False
|
||||||
for mo in re.finditer(self.MARKDOWN_KEYS_REGEX['CodeBlock'],text):
|
for mo in re.finditer(self.MARKDOWN_KEYS_REGEX['CodeBlock'],text):
|
||||||
stripped = text.lstrip()
|
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'])
|
self.setFormat(self.offset+ mo.start(), mo.end() - mo.start(), self.MARKDOWN_KWS_FORMAT['CodeBlock'])
|
||||||
found = True
|
found = True
|
||||||
return found
|
return found
|
||||||
|
Loading…
x
Reference in New Issue
Block a user