fix(output): replace spoilered text with '[Spoiler]' in plain text fallback

This commit is contained in:
Rye committed 2026-04-23 22:55:48 +02:00
1 parent c96947b746
commit 196bacdad4
2 files changed
+10 -2

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
default: patch
---
spoilered text now gets replaced with `[Spoiler]` in the plain text fallback, as per MSC4454
+5 -2
View File
@@ -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;
}