Add emoji processing

This commit is contained in:
Tim Clifford 2023-10-02 22:29:33 +01:00 committed by Maze
parent 294bd887ba
commit e99b7584d2

View File

@ -10,6 +10,7 @@ from urllib.parse import unquote
import html_sanitizer.sanitizer as sanitizer
import lxml.html # nosec
import emoji
import mistune
import nio
from html_sanitizer.sanitizer import Sanitizer
@ -215,6 +216,12 @@ class HTMLProcessor:
if not outgoing:
self._matrix_to_links_add_classes(a_tag)
for node in tree.iterdescendants():
if node.tag != "code" and node.text:
node.text = emoji.emojize(node.text, language="alias")
if node.getparent() and node.getparent().tag != "code" and node.tail:
node.tail = emoji.emojize(node.tail, language="alias")
html = etree.tostring(tree, encoding="utf-8", method="html").decode()
html = sanit.sanitize(html).rstrip("\n")