From 07fd598bf9337de0c2073064ebf85e9de663e501 Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Thu, 18 Aug 2022 12:56:21 +0200 Subject: [PATCH] fix: don't collapse whitespace / newlines --- 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 13c88667..155e0ebd 100644 --- a/src/components/markdown/RemarkRenderer.tsx +++ b/src/components/markdown/RemarkRenderer.tsx @@ -189,6 +189,11 @@ const RE_QUOTE = /(^(?:>\s){5})[>\s]+(.*$)/gm; */ const RE_HTML_TAGS = /^(<\/?[a-zA-Z0-9]+>)(.*$)/gm; +/** + * Regex for matching empty lines + */ +const RE_EMPTY_LINE = /^\s*?$/gm; + /** * Sanitise Markdown input before rendering * @param content Input string @@ -204,6 +209,11 @@ function sanitise(content: string) { // 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}`) + + // Replace empty lines with non-breaking space + // because remark renderer is collapsing empty + // or otherwise whitespace-only lines of text + .replace(RE_EMPTY_LINE, "‎") ); }