From 2c50d9be6b20d60057659f360d3827e992e90a1f Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Fri, 2 Sep 2022 16:29:20 +0100 Subject: [PATCH] chore: disable list behaviour if line starts with plus --- external/lang | 2 +- src/components/markdown/RemarkRenderer.tsx | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/external/lang b/external/lang index 7caef69b..bb3470b8 160000 --- a/external/lang +++ b/external/lang @@ -1 +1 @@ -Subproject commit 7caef69bad80de61d0bbaab16b45ff1359bfadfd +Subproject commit bb3470b838a3c8ffa39d11aaf5eef7fd92d97ae3 diff --git a/src/components/markdown/RemarkRenderer.tsx b/src/components/markdown/RemarkRenderer.tsx index 824e5ab0..71cf1d5e 100644 --- a/src/components/markdown/RemarkRenderer.tsx +++ b/src/components/markdown/RemarkRenderer.tsx @@ -199,6 +199,11 @@ const RE_HTML_TAGS = /^(<\/?[a-zA-Z0-9]+>)(.*$)/gm; */ const RE_EMPTY_LINE = /^\s*?$/gm; +/** + * Regex for matching line starting with plus + */ +const RE_PLUS = /^\s*\+(?:$|[^+])/gm; + /** * Sanitise Markdown input before rendering * @param content Input string @@ -215,6 +220,11 @@ function sanitise(content: string) { // https://github.com/revoltchat/revite/issues/733 .replace(RE_HTML_TAGS, (match) => `\u200E${match}`) + // Append empty character if line starts with a plus + // which would usually open a new list but we want + // to avoid that behaviour in our case. + .replace(RE_PLUS, (match) => `\u200E${match}`) + // Replace empty lines with non-breaking space // because remark renderer is collapsing empty // or otherwise whitespace-only lines of text