Escape subtext

This commit is contained in:
MarkusRost 2024-09-26 22:09:12 +00:00
parent f80c671964
commit 60d8251033

View file

@ -45,6 +45,7 @@ def sanitize_to_markdown(text: str) -> str:
text = text.replace("\\", "\\\\").replace('//', '/\\/').replace("](", "]\\(") # replace escaping and links text = text.replace("\\", "\\\\").replace('//', '/\\/').replace("](", "]\\(") # replace escaping and links
text = re.sub(r"([`_*~:<>{}@|])", "\\\\\\1", text) # Escape common Markdown characters text = re.sub(r"([`_*~:<>{}@|])", "\\\\\\1", text) # Escape common Markdown characters
text = re.sub(r"^(#+ )", '\\\\\\1', text, 0, re.MULTILINE) # Escape headers text = re.sub(r"^(#+ )", '\\\\\\1', text, 0, re.MULTILINE) # Escape headers
text = re.sub(r"^(-# )", '\\\\\\1', text, 0, re.MULTILINE) # Escape subtext
text = re.sub(r"^(\s*)- ", '\\1\\\\- ', text, 0, re.MULTILINE) # Escape lists text = re.sub(r"^(\s*)- ", '\\1\\\\- ', text, 0, re.MULTILINE) # Escape lists
text = re.sub(r"^(\s*\d+)\. ", "\\1\\\\. ", text, 0, re.MULTILINE) # Escape numbered lists text = re.sub(r"^(\s*\d+)\. ", "\\1\\\\. ", text, 0, re.MULTILINE) # Escape numbered lists
return text return text