<stylemedia="screen and (min-width: 700px)">@mediascreenand(min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em4em;border-left:1pxsolid#ddd}precode{font-size:1em}.item.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toculul,#indexul{padding-left:1.5em}.toc>ul>li{margin-top:.5em}}</style>
""" checks if text contains markdown symbols
:type text: string
:param text: text to check
:return: true if text contains markdown symbols
:rtype: bool
"""
if text.find("_") != -1 or text.find("*") != -1 or text.find("`") != -1: # check if text contains relevant markdown symbols
return True
return False
def make_markdown_proof(text): # used to avoid errors related to markdown parsemode for telegram messaging
""" makes text markdown proof
:type text: string
:param text: text to make markdown proof
:return: markdown proof text
:rtype: string
"""
text = str(text)
text = text.replace("_", "\\_") # replace _ with \_ because \ is used as escape character in markdown, double escape is needed because \ is also a escape character in strings
text = text.replace("*", "\\*")
text = text.replace("`", "\\`")
text = text.replace("[", "\\[")
text = text.replace("]", "\\]")
text = text.replace("(", "\\(")
text = text.replace(")", "\\)")
text = text.replace("#", "\\#")
text = text.replace("+", "\\+")
text = text.replace("-", "\\-")
text = text.replace("!", "\\!")
text = text.replace(".", "\\.")
text = text.replace("?", "\\?")
text = text.replace("/", "\\/")
text = text.replace("~", "\\~")
text = text.replace("|", "\\|")
text = text.replace("<", "\\<")
text = text.replace(">", "\\>")
text = text.replace("&", "\\&")
text = text.replace("^", "\\^")
text = text.replace("$", "\\$")
text = text.replace("%", "\\%")
text = text.replace("=", "\\=")
text = text.replace("@", "\\@")
return text
if __name__ == '__main__':
print("this is a module for helper functions for the bot and should not be run directly")
<pre><codeclass="python">def make_markdown_proof(text): # used to avoid errors related to markdown parsemode for telegram messaging
""" makes text markdown proof
:type text: string
:param text: text to make markdown proof
:return: markdown proof text
:rtype: string
"""
text = str(text)
text = text.replace("_", "\\_") # replace _ with \_ because \ is used as escape character in markdown, double escape is needed because \ is also a escape character in strings
text = text.replace("*", "\\*")
text = text.replace("`", "\\`")
text = text.replace("[", "\\[")
text = text.replace("]", "\\]")
text = text.replace("(", "\\(")
text = text.replace(")", "\\)")
text = text.replace("#", "\\#")
text = text.replace("+", "\\+")
text = text.replace("-", "\\-")
text = text.replace("!", "\\!")
text = text.replace(".", "\\.")
text = text.replace("?", "\\?")
text = text.replace("/", "\\/")
text = text.replace("~", "\\~")
text = text.replace("|", "\\|")
text = text.replace("<", "\\<")
text = text.replace(">", "\\>")
text = text.replace("&", "\\&")