update Discord markdown sanitation

This commit is contained in:
MarkusRost 2023-04-18 22:37:36 +00:00
parent 8dd1469f6d
commit bfc5e80553
2 changed files with 2 additions and 2 deletions

View file

@ -42,7 +42,7 @@ def clean_link(link: str) -> str:
def sanitize_to_markdown(text: str) -> str: def sanitize_to_markdown(text: str) -> str:
"""Sanitizes given text to escape markdown formatting. It is used in values that will be visible on Discord in messages""" """Sanitizes given text to escape markdown formatting. It is used in values that will be visible on Discord in messages"""
return re.sub(r"([`_*~:<>{}@|\\])", "\\\\\\1", text).replace('//', "/\\/").replace('](', "]\\(") return re.sub(r"([`_*~:<>{}@|#\-\.\\])", "\\\\\\1", text).replace('//', "/\\/").replace('](', "]\\(")
def sanitize_to_url(text: str) -> str: # TODO ) replaces needed? def sanitize_to_url(text: str) -> str: # TODO ) replaces needed?

View file

@ -173,7 +173,7 @@ class ContentParser(HTMLParser):
def handle_data(self, data): def handle_data(self, data):
def escape_formatting(data: str) -> str: def escape_formatting(data: str) -> str:
"""Escape Discord formatting""" """Escape Discord formatting"""
return re.sub(r"([`_*~<>{}@/|\\])", "\\\\\\1", data) return re.sub(r"([`_*~:<>{}@/|#\-\.\\\[\]\(\)])", "\\\\\\1", data)
data = escape_formatting(data) data = escape_formatting(data)
if self.current_tag == "ins" and self.ins_length <= 1000: if self.current_tag == "ins" and self.ins_length <= 1000:
self.ins_length += len("**" + data + "**") self.ins_length += len("**" + data + "**")