From a2cbe797875ca96394c5af1e69093c32b169eff0 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Sun, 29 Oct 2023 21:53:44 +1100 Subject: [PATCH] Fix broken emoji with md pattern in shortcode (#1514) * fix broken emoji with md pattern in shortcode * fix html regex when generating editor output --- src/app/components/editor/output.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/app/components/editor/output.ts b/src/app/components/editor/output.ts index fa15bb5..1fb2d59 100644 --- a/src/app/components/editor/output.ts +++ b/src/app/components/editor/output.ts @@ -51,21 +51,25 @@ const elementToCustomHtml = (node: CustomElement, children: string): string => { return ``; case BlockType.Mention: - return `${node.name}`; + return `${sanitizeText( + node.name + )}`; case BlockType.Emoticon: return node.key.startsWith('mxc://') - ? `${node.shortcode}` - : node.key; + ? `${sanitizeText(
+            node.shortcode
+          )}` + : sanitizeText(node.key); case BlockType.Link: - return `${node.children}`; + return `${node.children}`; case BlockType.Command: - return `/${node.command}`; + return `/${sanitizeText(node.command)}`; default: return children; } }; -const HTML_TAG_REG = /<([a-z]+)(?![^>]*\/>)[^<]*<\/\1>/; +const HTML_TAG_REG = /<([\w-]+)(?:[^/>]*)(?:(?:\/>)|(?:>.*?<\/\1>))/; const ignoreHTMLParseInlineMD = (text: string): string => { if (text === '') return text; const match = text.match(HTML_TAG_REG);