fix: render markdown inside/after HTML tags

fixes #733
This commit is contained in:
Leda 2022-07-17 19:19:34 +00:00 committed by Paul Makles
parent e9977b2a76
commit c2a729a5e0

View file

@ -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}`)
);
}