Add strikethrough/underline <-> unicode converter to formatter
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from html import escape
|
||||
import struct
|
||||
import re
|
||||
|
||||
@@ -31,3 +32,33 @@ HTML_REPLY_FALLBACK_REGEX = re.compile(r"^<blockquote data-mx-reply>[\s\S]+?</bl
|
||||
|
||||
def trim_reply_fallback_html(html):
|
||||
return HTML_REPLY_FALLBACK_REGEX.sub("", html)
|
||||
|
||||
|
||||
def unicode_to_html(text, html, ctrl, tag):
|
||||
if "\u0336" not in text and "\u0332" not in text:
|
||||
return html
|
||||
if not html:
|
||||
html = escape(text)
|
||||
tag_start = f"<{tag}>"
|
||||
tag_end = f"</{tag}>"
|
||||
characters = html.split(ctrl)
|
||||
html = ""
|
||||
in_del = False
|
||||
for char in characters:
|
||||
if not in_del:
|
||||
if len(char) > 1:
|
||||
html += char[0:-1]
|
||||
char = char[-1]
|
||||
html += tag_start
|
||||
in_del = True
|
||||
html += char
|
||||
else:
|
||||
if len(char) > 1:
|
||||
html += tag_end
|
||||
in_del = False
|
||||
html += char
|
||||
return html
|
||||
|
||||
|
||||
def html_to_unicode(text, ctrl):
|
||||
return ctrl.join(text) + ctrl
|
||||
|
||||
Reference in New Issue
Block a user