1
0
Fork 0

Escape markdown special characters in game name to avoid broken table.

This commit is contained in:
Casper V. Kristensen 2018-10-28 13:07:11 +01:00
parent 3a4bef19ed
commit c493442314
Signed by: caspervk
GPG key ID: B1156723DB3BDDA8
2 changed files with 11 additions and 1 deletions

View file

@ -333,7 +333,8 @@ class DailyReleasesBot(object):
else: else:
tags = " ({})".format(" ".join(rls["tags"])) if rls["tags"] else "" tags = " ({})".format(" ".join(rls["tags"])) if rls["tags"] else ""
highlights = " **- {}**".format(", ".join(rls["highlights"])) if rls["highlights"] else "" highlights = " **- {}**".format(", ".join(rls["highlights"])) if rls["highlights"] else ""
name = "[{}{}]({}){}".format(rls["game_name"], tags, rls["nfo_link"], highlights) name = "[{}{}]({}){}".format(util.markdown_escape(rls["game_name"]), tags, rls["nfo_link"],
highlights)
if rls["score"] == -1: if rls["score"] == -1:
reviews = "-" reviews = "-"

View file

@ -34,3 +34,12 @@ def case_insensitive_close_matches(word, possibilities, n=3, cutoff=0.6):
possibilities = {sequence.lower(): sequence for sequence in possibilities} possibilities = {sequence.lower(): sequence for sequence in possibilities}
close_matches = difflib.get_close_matches(word.lower(), possibilities, n=n, cutoff=cutoff) close_matches = difflib.get_close_matches(word.lower(), possibilities, n=n, cutoff=cutoff)
return [possibilities[m] for m in close_matches] return [possibilities[m] for m in close_matches]
def markdown_escape(text: str):
"""
Escape markdown.
"""
special = ("\\", "`", "*", "_", "{", "}", "[", "]", "(", ")", "#", "+", "-", ".", "!", "|")
table = {s: f"\\{s}" for s in special}
return text.translate(str.maketrans(table))