Skip to content

Commit cbb2251

Browse files
authored
Replace spoilered text with '[Spoiler]' in plain text fallback (SableClient#715)
### Description This pull request updates the plain text conversion logic to better handle spoilered text, ensuring that spoiler formatting is replaced with `[Spoiler]` in plain text fallbacks as per [MSC4454](matrix-org/matrix-spec-proposals#4454). **Spoiler handling improvements:** - Spoilered text (delimited by `||`) is now replaced with `[Spoiler]` in the plain text output, matching the MSC4454 specification. #### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings ### AI disclosure: - [ ] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). No AI involved
2 parents 005bbce + 02bd5b8 commit cbb2251

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

.changeset/msc4454.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: patch
3+
---
4+
5+
spoilered text now gets replaced with `[Spoiler]` in the plain text fallback, as per MSC4454

src/app/components/editor/output.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ const elementToPlainText = (node: CustomElement, children: string): string => {
197197
}
198198
};
199199

200+
const SPOILERINPUTREGEX = /\|\|.+?\|\|/g;
201+
200202
/**
201203
* convert slate internal representation to a plain text string that can be sent to the server
202204
* @param node the slate node
@@ -214,8 +216,9 @@ export const toPlainText = (
214216
if (Array.isArray(node))
215217
return node.map((n) => toPlainText(n, isMarkdown, stripNickname, nickNameReplacement)).join('');
216218
if (Text.isText(node)) {
219+
let { text } = node;
220+
text = text.replaceAll(SPOILERINPUTREGEX, '[Spoiler]');
217221
if (stripNickname && nickNameReplacement) {
218-
let { text } = node;
219222
nickNameReplacement?.keys().forEach((key) => {
220223
const replacement = nickNameReplacement.get(key) ?? '';
221224
text = text.replaceAll(key, replacement);
@@ -225,8 +228,8 @@ export const toPlainText = (
225228
: text;
226229
}
227230
return isMarkdown
228-
? unescapeMarkdownBlockSequences(node.text, unescapeMarkdownInlineSequences)
229-
: node.text;
231+
? unescapeMarkdownBlockSequences(text, unescapeMarkdownInlineSequences)
232+
: text;
230233
}
231234

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

0 commit comments

Comments
 (0)