mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
primitive support of bold-italic
This commit is contained in:
parent
6793aaae36
commit
918bd44f5d
@ -18,6 +18,8 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
||||
'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"},
|
||||
@ -133,6 +139,8 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
||||
|
||||
self.highlightBold(text, cursor, bf, strt)
|
||||
|
||||
self.highlightBoldEmphasis(text, cursor, bf, strt)
|
||||
|
||||
self.highlightLink(text, cursor, bf, strt)
|
||||
|
||||
self.highlightImage(text, cursor, bf, strt)
|
||||
@ -256,6 +264,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