mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
apply local bold/italic to Entity
This commit is contained in:
parent
cd888703b8
commit
c451efbd42
@ -73,7 +73,7 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
||||
"codeblock": {"color":"#ff5800", "font-weight":"normal", "font-style":"normal"},
|
||||
"line": {"color":"#2aa198", "font-weight":"normal", "font-style":"normal"},
|
||||
"html": {"color":"#c000c0", "font-weight":"normal", "font-style":"normal"},
|
||||
"entity": {"color":"#006496", "font-weight":"normal", "font-style":"normal"},
|
||||
"entity": {"color":"#006496"},
|
||||
}
|
||||
|
||||
dark_theme = {
|
||||
@ -90,7 +90,7 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
||||
"codeblock": {"color":"#ff9900", "font-weight":"normal", "font-style":"normal"},
|
||||
"line": {"color":"#2aa198", "font-weight":"normal", "font-style":"normal"},
|
||||
"html": {"color":"#f653a6", "font-weight":"normal", "font-style":"normal"},
|
||||
"entity": {"color":"#ff82ac", "font-weight":"normal", "font-style":"normal"},
|
||||
"entity": {"color":"#ff82ac"},
|
||||
}
|
||||
|
||||
def __init__(self, parent):
|
||||
@ -102,6 +102,16 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
||||
self.theme = theme
|
||||
self.MARKDOWN_KWS_FORMAT = {}
|
||||
|
||||
for k in ['Bold', 'Italic','BoldItalic']:
|
||||
# generate dynamically keys and theme for EntityBold, EntityItalic, EntityBoldItalic
|
||||
t = self.key_theme_maps[k]
|
||||
newtheme = theme['entity'].copy()
|
||||
newtheme.update(theme[t])
|
||||
newthemekey = 'entity'+t
|
||||
newmapkey = 'Entity'+k
|
||||
theme[newthemekey] = newtheme
|
||||
self.key_theme_maps[newmapkey] = newthemekey
|
||||
|
||||
for k,t in self.key_theme_maps.items():
|
||||
subtheme = theme[t]
|
||||
format = QTextCharFormat()
|
||||
@ -304,7 +314,18 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
||||
def highlightEntity(self, text, cursor, bf):
|
||||
found = False
|
||||
for mo in re.finditer(self.MARKDOWN_KEYS_REGEX['Entity'],text):
|
||||
self.setFormat(self.offset+ mo.start(), mo.end() - mo.start(), self.MARKDOWN_KWS_FORMAT['Entity'])
|
||||
charformat = self.format(self.offset+ mo.start())
|
||||
charbold = charformat.fontWeight() == QFont.Weight.Bold
|
||||
charitalic = charformat.fontItalic()
|
||||
if charbold and charitalic:
|
||||
format = self.MARKDOWN_KWS_FORMAT['EntityBoldItalic']
|
||||
elif charbold and not charitalic:
|
||||
format = self.MARKDOWN_KWS_FORMAT['EntityBold']
|
||||
elif not charbold and charitalic:
|
||||
format = self.MARKDOWN_KWS_FORMAT['EntityItalic']
|
||||
else:
|
||||
format = self.MARKDOWN_KWS_FORMAT['Entity']
|
||||
self.setFormat(self.offset+ mo.start(), mo.end() - mo.start(), format)
|
||||
found = True
|
||||
return found
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user