From 5828c378beff8bacdb2920d1dbe0dd1705d7937b Mon Sep 17 00:00:00 2001 From: miruka Date: Tue, 30 Mar 2021 18:39:17 -0400 Subject: [PATCH] Turn matrix.to links into shorter forms e.g. if someone posts a message containing "https://matrix.to/#/@foo:example.org", that link will be turned into a properly colored "@foo:example.org". --- src/backend/html_markdown.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/backend/html_markdown.py b/src/backend/html_markdown.py index ef077446..5a0ed51d 100644 --- a/src/backend/html_markdown.py +++ b/src/backend/html_markdown.py @@ -162,6 +162,8 @@ class HTMLProcessor: user_id_regex, room_id_regex, room_alias_regex, ]] + matrix_to_regex = re.compile(r"^https?://matrix.to/#/", re.IGNORECASE) + link_is_matrix_to_regex = re.compile( r"https?://matrix.to/#/\S+", re.IGNORECASE, ) @@ -526,6 +528,9 @@ class HTMLProcessor: if not href or not el.text: return el + + el.text = self.matrix_to_regex.sub("", el.text or "") + # This must be first, or link will be mistaken by room ID/alias regex if self.link_is_message_id_regex.match(href): el.attrib["class"] = "mention message-id-mention"