From 7b4b7509f32a8675d3a0ba2ded7a210adbf19c91 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 7 Mar 2018 14:50:36 +0200 Subject: [PATCH] Minor improvements to unicode->html formatter --- mautrix_telegram/formatter/util.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mautrix_telegram/formatter/util.py b/mautrix_telegram/formatter/util.py index 86c263fd..54502fbc 100644 --- a/mautrix_telegram/formatter/util.py +++ b/mautrix_telegram/formatter/util.py @@ -35,7 +35,7 @@ def trim_reply_fallback_html(html): 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 if not html: html = escape(text) @@ -43,20 +43,22 @@ def unicode_to_html(text, html, ctrl, tag): tag_end = f"" characters = html.split(ctrl) html = "" - in_del = False + in_tag = False for char in characters: - if not in_del: + if not in_tag: if len(char) > 1: html += char[0:-1] char = char[-1] html += tag_start - in_del = True + in_tag = True html += char else: if len(char) > 1: html += tag_end - in_del = False + in_tag = False html += char + if in_tag: + html += tag_end return html