From 3fc2e15faaea7e102c48494ed5d3f6f3afa62cda Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sun, 5 May 2019 15:17:45 +0200 Subject: [PATCH] Fix for reddit markdown not supporting escaping pipe character using backslash. --- dailyreleases/util.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/dailyreleases/util.py b/dailyreleases/util.py index 672e296..20727f5 100644 --- a/dailyreleases/util.py +++ b/dailyreleases/util.py @@ -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))