From e99b7584d28d585906eba5c82da6cbdac340d70a Mon Sep 17 00:00:00 2001 From: Tim Clifford Date: Mon, 2 Oct 2023 22:29:33 +0100 Subject: [PATCH] Add emoji processing --- src/backend/html_markdown.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/backend/html_markdown.py b/src/backend/html_markdown.py index 95fa8959..583b8b13 100644 --- a/src/backend/html_markdown.py +++ b/src/backend/html_markdown.py @@ -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")