Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit c7c51d7

Browse files
authored
Deserialise spoilers back into slash command form (#11805)
* Deserialise spoilers back into slash command form Fixes: element-hq/element-web#26344 * Appease the linter
1 parent b382a1c commit c7c51d7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/editor/deserialize.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ function parseNode(n: Node, pc: PartCreator, opts: IParseOptions, mkListItem?: (
247247

248248
return pc.plainWithEmoji(`${delimLeft}${tex}${delimRight}`);
249249
}
250+
// Spoilers are translated back into their slash command form
251+
else if ((n as Element).hasAttribute("data-mx-spoiler")) {
252+
return [pc.plain("/spoiler "), ...parseChildren(n, pc, opts)];
253+
}
250254
}
251255
}
252256

test/editor/deserialize-test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ describe("editor/deserialize", function () {
9898
expect(parts.length).toBe(1);
9999
expect(parts[0]).toStrictEqual({ type: "plain", text: "/me says DON'T SHOUT!" });
100100
});
101+
it("spoiler", function () {
102+
const parts = normalize(parseEvent(textMessage("/spoiler broiler"), createPartCreator()));
103+
expect(parts.length).toBe(1);
104+
expect(parts[0]).toStrictEqual({ type: "plain", text: "/spoiler broiler" });
105+
});
101106
});
102107
describe("html messages", function () {
103108
it("inline styling", function () {
@@ -295,6 +300,13 @@ describe("editor/deserialize", function () {
295300
expect(parts.length).toBe(1);
296301
expect(parts[0]).toStrictEqual({ type: "plain", text: "/me says _DON'T SHOUT_!" });
297302
});
303+
it("spoiler", function () {
304+
const parts = normalize(
305+
parseEvent(htmlMessage("<span data-mx-spoiler>broiler</span>"), createPartCreator()),
306+
);
307+
expect(parts.length).toBe(1);
308+
expect(parts[0]).toStrictEqual({ type: "plain", text: "/spoiler broiler" });
309+
});
298310
it("preserves nested quotes", () => {
299311
const html = "<blockquote>foo<blockquote>bar</blockquote></blockquote>";
300312
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));

0 commit comments

Comments
 (0)