Fix > parsing and local echo
This commit is contained in:
parent
459880903d
commit
843d40ca26
|
@ -43,23 +43,26 @@ class HtmlFilter:
|
|||
]
|
||||
|
||||
|
||||
def from_markdown(self, text: str) -> str:
|
||||
return self.filter(self._markdown_to_html(text))
|
||||
def from_markdown(self, text: str, outgoing: bool = False) -> str:
|
||||
return self.filter(self._markdown_to_html(text), outgoing)
|
||||
|
||||
|
||||
def from_markdown_inline(self, text: str) -> str:
|
||||
return self.filter_inline(self._markdown_to_html(text))
|
||||
def from_markdown_inline(self, text: str, outgoing: bool = False) -> str:
|
||||
return self.filter_inline(self._markdown_to_html(text), outgoing)
|
||||
|
||||
|
||||
def filter_inline(self, html: str) -> str:
|
||||
def filter_inline(self, html: str, outgoing: bool = False) -> str:
|
||||
text = self._inline_sanitizer.sanitize(html).strip("\n")
|
||||
|
||||
if not outgoing:
|
||||
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, outgoing: bool = False) -> str:
|
||||
html = self._sanitizer.sanitize(html)
|
||||
tree = etree.fromstring(html, parser=etree.HTMLParser())
|
||||
|
||||
|
@ -76,11 +79,14 @@ class HtmlFilter:
|
|||
for el in tree[0].iterchildren()))
|
||||
|
||||
text = str(result, "utf-8").strip("\n")
|
||||
|
||||
if not outgoing:
|
||||
text = re.sub(
|
||||
r"<(p|br/?)>(\s*>.+)(!?<(?:br|p)/?>)",
|
||||
r"<(p|br/?)>(\s*>.*)(!?</?(?:br|p)/?>)",
|
||||
r'<\1><span class="greentext">\2</span>\3',
|
||||
text
|
||||
)
|
||||
|
||||
return text
|
||||
|
||||
|
||||
|
|
|
@ -162,13 +162,15 @@ class MatrixClient(nio.AsyncClient):
|
|||
event_type = nio.RoomMessageEmote
|
||||
text = text[len("/me "): ]
|
||||
content = {"body": text, "msgtype": "m.emote"}
|
||||
to_html = HTML_FILTER.from_markdown_inline(text)
|
||||
to_html = HTML_FILTER.from_markdown_inline(text, outgoing=True)
|
||||
echo_html = HTML_FILTER.from_markdown_inline(text)
|
||||
else:
|
||||
event_type = nio.RoomMessageText
|
||||
content = {"body": text, "msgtype": "m.text"}
|
||||
to_html = HTML_FILTER.from_markdown(text)
|
||||
to_html = HTML_FILTER.from_markdown(text, outgoing=True)
|
||||
echo_html = HTML_FILTER.from_markdown(text)
|
||||
|
||||
if to_html not in (text, f"<p>{text}</p>"):
|
||||
if to_html not in (html.escape(text), f"<p>{html.escape(text)}</p>"):
|
||||
content["format"] = "org.matrix.custom.html"
|
||||
content["formatted_body"] = to_html
|
||||
|
||||
|
@ -178,7 +180,7 @@ class MatrixClient(nio.AsyncClient):
|
|||
event_id = f"local_echo.{uuid4()}",
|
||||
sender_id = self.user_id,
|
||||
date = datetime.now(),
|
||||
content = to_html,
|
||||
content = echo_html,
|
||||
is_local_echo = True,
|
||||
)
|
||||
|
||||
|
|
|
@ -66,10 +66,8 @@ Row {
|
|||
id: contentLabel
|
||||
width: parent.width
|
||||
|
||||
Component.onCompleted: print(text)
|
||||
text: '<style type="text/css">' +
|
||||
theme.chat.message.stylesheet +
|
||||
'</style>' +
|
||||
Component.onCompleted: print(text, "\n")
|
||||
text: theme.chat.message.styleInclude +
|
||||
Utils.processedEventText(model) +
|
||||
// time
|
||||
" <font size=" + theme.fontSize.small +
|
||||
|
|
|
@ -120,8 +120,11 @@ QtObject {
|
|||
|
||||
property color greenTextColor: Ut.hsl(80, 60, 25)
|
||||
|
||||
property string stylesheet:
|
||||
property string styleSheet:
|
||||
".greentext { color: " + greenTextColor + " }"
|
||||
|
||||
property string styleInclude:
|
||||
'<style type"text/css">\n' + styleSheet + '\n</style>\n'
|
||||
}
|
||||
|
||||
property QtObject daybreak: QtObject {
|
||||
|
|
Loading…
Reference in New Issue
Block a user