Message stylesheet; turn "> ..." into greentext
This commit is contained in:
parent
6e65376612
commit
459880903d
|
@ -11,8 +11,7 @@ from html_sanitizer.sanitizer import Sanitizer
|
||||||
|
|
||||||
|
|
||||||
class MarkdownRenderer(mistune.Renderer):
|
class MarkdownRenderer(mistune.Renderer):
|
||||||
def block_quote(self, text: str) -> str:
|
pass
|
||||||
return re.sub(r"^<p>", "<p>>", text)
|
|
||||||
|
|
||||||
|
|
||||||
class HtmlFilter:
|
class HtmlFilter:
|
||||||
|
@ -53,7 +52,11 @@ class HtmlFilter:
|
||||||
|
|
||||||
|
|
||||||
def filter_inline(self, html: str) -> str:
|
def filter_inline(self, html: str) -> str:
|
||||||
return self._inline_sanitizer.sanitize(html).strip("\n")
|
text = self._inline_sanitizer.sanitize(html).strip("\n")
|
||||||
|
text = re.sub(
|
||||||
|
r"(^\s*>.*)", r'<span class="greentext">\1</span>', text
|
||||||
|
)
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
def filter(self, html: str) -> str:
|
def filter(self, html: str) -> str:
|
||||||
|
@ -72,7 +75,13 @@ class HtmlFilter:
|
||||||
result = b"".join((etree.tostring(el, encoding="utf-8")
|
result = b"".join((etree.tostring(el, encoding="utf-8")
|
||||||
for el in tree[0].iterchildren()))
|
for el in tree[0].iterchildren()))
|
||||||
|
|
||||||
return str(result, "utf-8").strip("\n")
|
text = str(result, "utf-8").strip("\n")
|
||||||
|
text = re.sub(
|
||||||
|
r"<(p|br/?)>(\s*>.+)(!?<(?:br|p)/?>)",
|
||||||
|
r'<\1><span class="greentext">\2</span>\3',
|
||||||
|
text
|
||||||
|
)
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
def sanitize_settings(self, inline: bool = False) -> dict:
|
def sanitize_settings(self, inline: bool = False) -> dict:
|
||||||
|
@ -88,8 +97,8 @@ class HtmlFilter:
|
||||||
}
|
}
|
||||||
|
|
||||||
inlines_attributes = {
|
inlines_attributes = {
|
||||||
# TODO: translate font attrs to qt html subset, disallow color
|
# TODO: translate font attrs to qt html subset
|
||||||
"font": {"data-mx-bg-color", "data-mx-color", "color"},
|
"font": {"data-mx-bg-color", "data-mx-color"},
|
||||||
"a": {"href"},
|
"a": {"href"},
|
||||||
"code": {"class"},
|
"code": {"class"},
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,11 @@ Row {
|
||||||
id: contentLabel
|
id: contentLabel
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
|
||||||
text: Utils.processedEventText(model) +
|
Component.onCompleted: print(text)
|
||||||
|
text: '<style type="text/css">' +
|
||||||
|
theme.chat.message.stylesheet +
|
||||||
|
'</style>' +
|
||||||
|
Utils.processedEventText(model) +
|
||||||
// time
|
// time
|
||||||
" <font size=" + theme.fontSize.small +
|
" <font size=" + theme.fontSize.small +
|
||||||
"px color=" + theme.chat.message.date + ">" +
|
"px color=" + theme.chat.message.date + ">" +
|
||||||
|
|
|
@ -117,6 +117,11 @@ QtObject {
|
||||||
property color background: colors.background2
|
property color background: colors.background2
|
||||||
property color body: colors.foreground
|
property color body: colors.foreground
|
||||||
property color date: colors.foregroundDim
|
property color date: colors.foregroundDim
|
||||||
|
|
||||||
|
property color greenTextColor: Ut.hsl(80, 60, 25)
|
||||||
|
|
||||||
|
property string stylesheet:
|
||||||
|
".greentext { color: " + greenTextColor + " }"
|
||||||
}
|
}
|
||||||
|
|
||||||
property QtObject daybreak: QtObject {
|
property QtObject daybreak: QtObject {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user