Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/msc4454.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

spoilered text now gets replaced with `[Spoiler]` in the plain text fallback, as per MSC4454
9 changes: 6 additions & 3 deletions src/app/components/editor/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -224,8 +227,8 @@ export const toPlainText = (
: text;
}
return isMarkdown
? unescapeMarkdownBlockSequences(node.text, unescapeMarkdownInlineSequences)
: node.text;
? unescapeMarkdownBlockSequences(text, unescapeMarkdownInlineSequences)
: text;
}

const children = node.children.map((n) => toPlainText(n, isMarkdown)).join('');
Expand Down
Loading