transliteration-decoder: implement proper HTML escaping and add new transliteration model

This commit is contained in:
dymik739 2023-10-29 21:13:48 +02:00
parent ec22c72afb
commit 51307b5234
2 changed files with 61 additions and 3 deletions

View File

@ -4,8 +4,14 @@ command_length = len(command)
def escaped_string(unescaped_string):
result_string = str(unescaped_string)
for i in ["<", ">"]:
result_string = result_string.replace(i, f"\\{i}")
escaping_rules = {
"<": "&lt;",
">": "&gt;",
'"': "&quot;"
}
for i in escaping_rules.items():
result_string = result_string.replace(i[0], i[1])
return result_string
@ -31,7 +37,7 @@ if (command[0] in self.aliases) and (1 <= command_length <= 3):
f"{', '.join(list(models.keys()))}"
else:
for i in models[chosen_model]:
decoded_text = decoded_text.replace(i[0], i[1])
decoded_text = decoded_text.replace(i[0].lower(), i[1].lower())
decoded_text = decoded_text.replace(i[0].capitalize(), i[1].capitalize())
decoded_text = decoded_text.replace(i[0].upper(), i[1].upper())

View File

@ -75,5 +75,57 @@
["$", ";"],
["^", ":"],
["&", "?"]
],
"en-men": [
["a", "4"],
["b", "8"],
["c", "("],
["d", "|)"],
["e", "3"],
["f", "|="],
["g", "6"],
["h", "#"],
["i", "!"],
["j", "|_"],
["k", "|<"],
["l", "1"],
["m", "//N"],
["o", "0"],
["p", "|D"],
["q", "(,)"],
["r", "|2"],
["s", "5"],
["t", "7"],
["u", "|_|"],
["w", "//"],
["v", "/"],
["x", "><"],
["y", "`/"]
],
"men-en": [
["4", "a"],
["8", "b"],
["(,)", "q"],
["(", "c"],
["|)", "d"],
["3", "e"],
["|=", "f"],
["6", "g"],
["#", "h"],
["!", "i"],
["|_|", "u"],
["|_", "j"],
["|<", "k"],
["1", "l"],
["//N", "m"],
["0", "o"],
["|D", "p"],
["|2", "r"],
["5", "s"],
["7", "t"],
["//", "w"],
["`/", "y"],
["/", "v"],
["><", "x"]
]
}