From 924666ab1da8b075cf2d691024afc9c0983a7656 Mon Sep 17 00:00:00 2001 From: git-bruh Date: Wed, 28 Sep 2022 17:02:07 +0530 Subject: [PATCH] appservice: HTML fixes --- appservice/main.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/appservice/main.py b/appservice/main.py index 4bfd5a2..4c635fe 100644 --- a/appservice/main.py +++ b/appservice/main.py @@ -218,7 +218,7 @@ class MatrixClient(AppService): fmt = self.get_fmt(message, emotes) - if len(fmt) != len(message): + if fmt != message: content = { **content, "format": "org.matrix.custom.html", @@ -261,7 +261,13 @@ class MatrixClient(AppService): event.body = tmp event.formatted_body = ( - re.sub(".*", "", event.formatted_body) + # re.DOTALL allows the match to span newlines. + re.sub( + "", + "", + event.formatted_body, + flags=re.DOTALL, + ) if event.formatted_body else event.body ) @@ -274,10 +280,9 @@ class MatrixClient(AppService): "m.relates_to": {"m.in_reply_to": {"event_id": event.id}}, "format": "org.matrix.custom.html", "formatted_body": f"""
\ -\ -In reply to\ -{event.sender}
\ -{event.formatted_body if event.formatted_body else event.body}\ +In reply to\ +{event.sender}\ +
{event.formatted_body if event.formatted_body else event.body}\
\ {content.get("formatted_body", content['body'])}""", } @@ -295,7 +300,10 @@ In reply to\ def get_fmt(self, message: str, emotes: dict) -> str: message = ( - markdown.markdown(message).replace("

", "").replace("

", "") + markdown.markdown(message) + .replace("

", "") + .replace("

", "") + .replace("\n", "
") ) # Upload emotes in multiple threads so that we don't