From c2a729a5e0edc2152ce29625d1da89ecc21b0167 Mon Sep 17 00:00:00 2001 From: Leda Date: Sun, 17 Jul 2022 19:19:34 +0000 Subject: [PATCH] fix: render markdown inside/after HTML tags fixes #733 --- src/components/markdown/RemarkRenderer.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/markdown/RemarkRenderer.tsx b/src/components/markdown/RemarkRenderer.tsx index e3b2f3d6..13c88667 100644 --- a/src/components/markdown/RemarkRenderer.tsx +++ b/src/components/markdown/RemarkRenderer.tsx @@ -184,6 +184,11 @@ const Container = styled.div<{ largeEmoji: boolean }>` */ const RE_QUOTE = /(^(?:>\s){5})[>\s]+(.*$)/gm; +/** + * Regex for matching HTML tags + */ +const RE_HTML_TAGS = /^(<\/?[a-zA-Z0-9]+>)(.*$)/gm; + /** * Sanitise Markdown input before rendering * @param content Input string @@ -194,6 +199,11 @@ function sanitise(content: string) { content // Strip excessive blockquote indentation .replace(RE_QUOTE, (_, m0, m1) => m0 + m1) + + // Append empty character if string starts with html tag + // This is to avoid inconsistencies in rendering Markdown inside/after HTML tags + // https://github.com/revoltchat/revite/issues/733 + .replace(RE_HTML_TAGS, (match) => `\u200E${match}`) ); }