From 196bacdad4318057e1ec34605280cff3a7eabffc Mon Sep 17 00:00:00 2001 From: Rye Date: Thu, 23 Apr 2026 22:55:48 +0200 Subject: [PATCH 1/2] fix(output): replace spoilered text with '[Spoiler]' in plain text fallback --- .changeset/msc4454.md | 5 +++++ src/app/components/editor/output.ts | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .changeset/msc4454.md diff --git a/.changeset/msc4454.md b/.changeset/msc4454.md new file mode 100644 index 000000000..af548e99e --- /dev/null +++ b/.changeset/msc4454.md @@ -0,0 +1,5 @@ +--- +default: patch +--- + +spoilered text now gets replaced with `[Spoiler]` in the plain text fallback, as per MSC4454 diff --git a/src/app/components/editor/output.ts b/src/app/components/editor/output.ts index 383678e1a..3feca8010 100644 --- a/src/app/components/editor/output.ts +++ b/src/app/components/editor/output.ts @@ -196,6 +196,8 @@ const elementToPlainText = (node: CustomElement, children: string): string => { } }; +const SPOILERINPUTREGEX = /\|\|.+?\|\|/g; + /** * convert slate internal representation to a plain text string that can be sent to the server * @param node the slate node @@ -213,8 +215,9 @@ export const toPlainText = ( if (Array.isArray(node)) return node.map((n) => toPlainText(n, isMarkdown, stripNickname, nickNameReplacement)).join(''); if (Text.isText(node)) { + let { text } = node; + text = text.replaceAll(SPOILERINPUTREGEX, '[Spoiler]'); if (stripNickname && nickNameReplacement) { - let { text } = node; nickNameReplacement?.keys().forEach((key) => { const replacement = nickNameReplacement.get(key) ?? ''; text = text.replaceAll(key, replacement); @@ -224,7 +227,7 @@ export const toPlainText = ( : text; } return isMarkdown - ? unescapeMarkdownBlockSequences(node.text, unescapeMarkdownInlineSequences) + ? unescapeMarkdownBlockSequences(text, unescapeMarkdownInlineSequences) : node.text; } From 02bd5b87487d4b92edc2f511490d852baeb7d465 Mon Sep 17 00:00:00 2001 From: Rose Date: Thu, 23 Apr 2026 23:36:27 +0200 Subject: [PATCH 2/2] Fix text return in toPlainText function --- src/app/components/editor/output.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/editor/output.ts b/src/app/components/editor/output.ts index 3feca8010..4b6cab231 100644 --- a/src/app/components/editor/output.ts +++ b/src/app/components/editor/output.ts @@ -228,7 +228,7 @@ export const toPlainText = ( } return isMarkdown ? unescapeMarkdownBlockSequences(text, unescapeMarkdownInlineSequences) - : node.text; + : text; } const children = node.children.map((n) => toPlainText(n, isMarkdown)).join('');