Escape markdown special characters in game name to avoid broken table.
This commit is contained in:
parent
3a4bef19ed
commit
c493442314
|
@ -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 = "-"
|
||||||
|
|
|
@ -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))
|
||||||
|
|
Reference in a new issue