mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'fix-markdown-highlighter' of https://github.com/un-pogaz/calibre
This commit is contained in:
commit
0d8a563d2d
@ -15,9 +15,11 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
||||
|
||||
MARKDOWN_KEYS_REGEX = {
|
||||
'Bold' : re.compile(r'(?P<delim>\*\*)(?P<text>.+)(?P=delim)'),
|
||||
'uBold': re.compile('(?P<delim>__)(?P<text>[^_]{2,})(?P=delim)'),
|
||||
'Italic': re.compile(r'(?P<delim>\*)(?P<text>[^*]{2,})(?P=delim)'),
|
||||
'uItalic': re.compile('(?P<delim>_)(?P<text>[^_]+)(?P=delim)'),
|
||||
'uBold': re.compile('(?P<delim>__)(?P<text>.+)(?P=delim)'),
|
||||
'Italic': re.compile(r'(?P<delim>\*)(?P<text>([^*]{2,}|[^*]))(?P=delim)'),
|
||||
'uItalic': re.compile('(?P<delim>_)(?P<text>([^_]{2,}|[^_]))(?P=delim)'),
|
||||
'BoldItalic': 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)(^|(?P<pre>[^!]))\[.*?\]:?[ ''\t'r']*\(?[^)]+\)?'),
|
||||
'Image': re.compile(r'(?u)!\[.*?\]\(.+?\)'),
|
||||
'HeaderAtx': re.compile(r'(?u)^\#{1,6}(.*?)\#*(''\n|$)'),
|
||||
@ -39,6 +41,8 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
||||
'uBold': "bold",
|
||||
'Italic': "emphasis",
|
||||
'uItalic': "emphasis",
|
||||
'BoldItalic': "boldemphasis",
|
||||
'uBoldItalic': "boldemphasis",
|
||||
'Link': "link",
|
||||
'Image': "image",
|
||||
'HeaderAtx': "header",
|
||||
@ -58,6 +62,7 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
||||
light_theme = {
|
||||
"bold": {"font-weight":"bold"},
|
||||
"emphasis": {"font-style":"italic"},
|
||||
"boldemphasis": {"font-weight":"bold", "font-style":"italic"},
|
||||
"link": {"color":light_link_color.name(), "font-weight":"normal", "font-style":"normal"},
|
||||
"image": {"color":"#cb4b16", "font-weight":"normal", "font-style":"normal"},
|
||||
"header": {"color":"#2aa198", "font-weight":"bold", "font-style":"normal"},
|
||||
@ -73,6 +78,7 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
||||
dark_theme = {
|
||||
"bold": {"font-weight":"bold"},
|
||||
"emphasis": {"font-style":"italic"},
|
||||
"boldemphasis": {"font-weight":"bold", "font-style":"italic"},
|
||||
"link": {"color":dark_link_color.name(), "font-weight":"normal", "font-style":"normal"},
|
||||
"image": {"color":"#cb4b16", "font-weight":"normal", "font-style":"normal"},
|
||||
"header": {"color":"#2aa198", "font-weight":"bold", "font-style":"normal"},
|
||||
@ -129,16 +135,18 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
||||
|
||||
self.highlightList(text, cursor, bf, strt)
|
||||
|
||||
self.highlightEmphasis(text, cursor, bf, strt)
|
||||
|
||||
self.highlightBold(text, cursor, bf, strt)
|
||||
|
||||
self.highlightBoldEmphasis(text, cursor, bf, strt)
|
||||
|
||||
self.highlightLink(text, cursor, bf, strt)
|
||||
|
||||
self.highlightImage(text, cursor, bf, strt)
|
||||
|
||||
self.highlightCodeSpan(text, cursor, bf, strt)
|
||||
|
||||
self.highlightEmphasis(text, cursor, bf, strt)
|
||||
|
||||
self.highlightBold(text, cursor, bf, strt)
|
||||
|
||||
self.highlightCodeBlock(text, cursor, bf, strt)
|
||||
|
||||
def highlightBlockQuote(self, text, cursor, bf, strt):
|
||||
@ -211,7 +219,9 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
||||
def highlightLink(self, text, cursor, bf, strt):
|
||||
found = False
|
||||
for mo in re.finditer(self.MARKDOWN_KEYS_REGEX['Link'],text):
|
||||
self.setFormat(mo.start()+strt, mo.end() - mo.start()-strt, self.MARKDOWN_KWS_FORMAT['Link'])
|
||||
start_bracket = mo.group()[0][0] == '['
|
||||
self.setFormat(mo.start() + strt + (0 if start_bracket else 1),
|
||||
mo.end() - mo.start() - strt - (0 if start_bracket else 1), self.MARKDOWN_KWS_FORMAT['Link'])
|
||||
found = True
|
||||
return found
|
||||
|
||||
@ -255,6 +265,17 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
||||
found = True
|
||||
return found
|
||||
|
||||
def highlightBoldEmphasis(self, text, cursor, bf, strt):
|
||||
found = False
|
||||
for mo in re.finditer(self.MARKDOWN_KEYS_REGEX['BoldItalic'],text):
|
||||
self.setFormat(mo.start()+strt, mo.end() - mo.start()-strt, self.MARKDOWN_KWS_FORMAT['BoldItalic'])
|
||||
found = True
|
||||
|
||||
for mo in re.finditer(self.MARKDOWN_KEYS_REGEX['uBoldItalic'],text):
|
||||
self.setFormat(mo.start()+strt, mo.end() - mo.start()-strt, self.MARKDOWN_KWS_FORMAT['uBoldItalic'])
|
||||
found = True
|
||||
return found
|
||||
|
||||
def highlightCodeBlock(self, text, cursor, bf, strt):
|
||||
found = False
|
||||
for mo in re.finditer(self.MARKDOWN_KEYS_REGEX['CodeBlock'],text):
|
||||
|
Loading…
x
Reference in New Issue
Block a user