Minor improvements to unicode->html formatter

This commit is contained in:
Tulir Asokan
2018-03-07 14:50:36 +02:00
parent 8bbd1f7db1
commit 7b4b7509f3
+7 -5
View File
@@ -35,7 +35,7 @@ def trim_reply_fallback_html(html):
def unicode_to_html(text, html, ctrl, tag): def unicode_to_html(text, html, ctrl, tag):
if "\u0336" not in text and "\u0332" not in text: if ctrl not in text:
return html return html
if not html: if not html:
html = escape(text) html = escape(text)
@@ -43,20 +43,22 @@ def unicode_to_html(text, html, ctrl, tag):
tag_end = f"</{tag}>" tag_end = f"</{tag}>"
characters = html.split(ctrl) characters = html.split(ctrl)
html = "" html = ""
in_del = False in_tag = False
for char in characters: for char in characters:
if not in_del: if not in_tag:
if len(char) > 1: if len(char) > 1:
html += char[0:-1] html += char[0:-1]
char = char[-1] char = char[-1]
html += tag_start html += tag_start
in_del = True in_tag = True
html += char html += char
else: else:
if len(char) > 1: if len(char) > 1:
html += tag_end html += tag_end
in_del = False in_tag = False
html += char html += char
if in_tag:
html += tag_end
return html return html