Created
July 9, 2020 06:34
-
-
Save klrkdekira/36a043c6e2fa0193a26b6c833101788e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tobold(text): | |
return md.bold(text) | |
# using tobold == md.bold | |
# because tobold(text) == md.bold(text) | |
# fun fact, you can alias the function | |
# tobold = md.bold | |
# unless you want to pre fill parameter | |
def header(text): | |
return md.header(text, 1) | |
def toitalic(text): | |
return md.italics(text) | |
def tostrike(text): | |
return md.strikethrough(text) | |
def tomono(text): | |
return md.bold(text) | |
def format_msg(tag,msg): | |
switcher={ | |
'b': tobold(msg), | |
'i': toitalic(msg), | |
's': tostrike(msg), | |
} | |
# switcher will create a copy of the result of each | |
# even if you're not using it | |
return switcher.get(tag,msg) | |
# switcher can be outside since it only need to be initialised once | |
# also most importantly switcher is not intended to be mutated | |
switcher = { | |
'b': md.bold, | |
'i': md.italics, | |
's': md.strikethrough, | |
} | |
def format_msg_minimal(tag, msg): | |
func = switcher.get(tag) | |
if not func: | |
return msg # not formatted | |
return func(msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment