appservice: HTML fixes
This commit is contained in:
parent
26a8bcffa6
commit
924666ab1d
1 changed files with 15 additions and 7 deletions
|
@ -218,7 +218,7 @@ class MatrixClient(AppService):
|
||||||
|
|
||||||
fmt = self.get_fmt(message, emotes)
|
fmt = self.get_fmt(message, emotes)
|
||||||
|
|
||||||
if len(fmt) != len(message):
|
if fmt != message:
|
||||||
content = {
|
content = {
|
||||||
**content,
|
**content,
|
||||||
"format": "org.matrix.custom.html",
|
"format": "org.matrix.custom.html",
|
||||||
|
@ -261,7 +261,13 @@ class MatrixClient(AppService):
|
||||||
|
|
||||||
event.body = tmp
|
event.body = tmp
|
||||||
event.formatted_body = (
|
event.formatted_body = (
|
||||||
re.sub("<mx-reply>.*</mx-reply>", "", event.formatted_body)
|
# re.DOTALL allows the match to span newlines.
|
||||||
|
re.sub(
|
||||||
|
"<mx-reply.+?</mx-reply>",
|
||||||
|
"",
|
||||||
|
event.formatted_body,
|
||||||
|
flags=re.DOTALL,
|
||||||
|
)
|
||||||
if event.formatted_body
|
if event.formatted_body
|
||||||
else event.body
|
else event.body
|
||||||
)
|
)
|
||||||
|
@ -274,10 +280,9 @@ class MatrixClient(AppService):
|
||||||
"m.relates_to": {"m.in_reply_to": {"event_id": event.id}},
|
"m.relates_to": {"m.in_reply_to": {"event_id": event.id}},
|
||||||
"format": "org.matrix.custom.html",
|
"format": "org.matrix.custom.html",
|
||||||
"formatted_body": f"""<mx-reply><blockquote>\
|
"formatted_body": f"""<mx-reply><blockquote>\
|
||||||
<a href="https://matrix.to/#/{event.room_id}/{event.id}">\
|
<a href="https://matrix.to/#/{event.room_id}/{event.id}">In reply to</a>\
|
||||||
In reply to</a><a href="https://matrix.to/#/{event.sender}">\
|
<a href="https://matrix.to/#/{event.sender}">{event.sender}</a>\
|
||||||
{event.sender}</a><br>\
|
<br />{event.formatted_body if event.formatted_body else event.body}\
|
||||||
{event.formatted_body if event.formatted_body else event.body}\
|
|
||||||
</blockquote></mx-reply>\
|
</blockquote></mx-reply>\
|
||||||
{content.get("formatted_body", content['body'])}""",
|
{content.get("formatted_body", content['body'])}""",
|
||||||
}
|
}
|
||||||
|
@ -295,7 +300,10 @@ In reply to</a><a href="https://matrix.to/#/{event.sender}">\
|
||||||
|
|
||||||
def get_fmt(self, message: str, emotes: dict) -> str:
|
def get_fmt(self, message: str, emotes: dict) -> str:
|
||||||
message = (
|
message = (
|
||||||
markdown.markdown(message).replace("<p>", "").replace("</p>", "")
|
markdown.markdown(message)
|
||||||
|
.replace("<p>", "")
|
||||||
|
.replace("</p>", "")
|
||||||
|
.replace("\n", "<br />")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Upload emotes in multiple threads so that we don't
|
# Upload emotes in multiple threads so that we don't
|
||||||
|
|
Loading…
Reference in a new issue