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".
This commit is contained in:
parent
c8bf607fc2
commit
5828c378be
|
@ -162,6 +162,8 @@ class HTMLProcessor:
|
||||||
user_id_regex, room_id_regex, room_alias_regex,
|
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(
|
link_is_matrix_to_regex = re.compile(
|
||||||
r"https?://matrix.to/#/\S+", re.IGNORECASE,
|
r"https?://matrix.to/#/\S+", re.IGNORECASE,
|
||||||
)
|
)
|
||||||
|
@ -526,6 +528,9 @@ class HTMLProcessor:
|
||||||
if not href or not el.text:
|
if not href or not el.text:
|
||||||
return el
|
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
|
# This must be first, or link will be mistaken by room ID/alias regex
|
||||||
if self.link_is_message_id_regex.match(href):
|
if self.link_is_message_id_regex.match(href):
|
||||||
el.attrib["class"] = "mention message-id-mention"
|
el.attrib["class"] = "mention message-id-mention"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user