1
0
Fork 0

Fix for reddit markdown not supporting escaping pipe character using backslash.

This commit is contained in:
Casper V. Kristensen 2019-05-05 15:17:45 +02:00
parent 3c972da834
commit 3fc2e15faa
Signed by: caspervk
GPG key ID: 289CA03790535054

View file

@ -39,8 +39,25 @@ def case_insensitive_close_matches(word: str, possibilities: Sequence[str], n=3,
def markdown_escape(text: str) -> str:
"""
Escape markdown.
Escape reddit markdown.
"""
special = ("\\", "`", "*", "_", "{", "}", "[", "]", "(", ")", "#", "+", "-", ".", "!", "|")
table = {s: f"\\{s}" for s in special}
table = {
"\\": "\\\\",
"`": "\\`",
"*": "\\*",
"_": "\\_",
"{": "\\{",
"}": "\\}",
"[": "\\[",
"]": "\\]",
"(": "\\(",
")": "\\)",
"#": "\\#",
"+": "\\+",
"-": "\\-",
".": "\\.",
"!": "\\!",
"~": "\\~",
"|": "|",
}
return text.translate(str.maketrans(table))