From 1251869128140d6f02335ec02538c96fe7e48cdb Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Thu, 26 Oct 2023 14:46:55 +0200 Subject: [PATCH 1/2] Deserialise spoilers back into slash command form Fixes: vector-im/element-web#26344 --- src/editor/deserialize.ts | 4 ++++ test/editor/deserialize-test.ts | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/editor/deserialize.ts b/src/editor/deserialize.ts index 3b9c1cee2c3..1d2d1f6b29b 100644 --- a/src/editor/deserialize.ts +++ b/src/editor/deserialize.ts @@ -247,6 +247,10 @@ function parseNode(n: Node, pc: PartCreator, opts: IParseOptions, mkListItem?: ( return pc.plainWithEmoji(`${delimLeft}${tex}${delimRight}`); } + // Spoilers are translated back into their slash command form + else if ((n as Element).hasAttribute("data-mx-spoiler")) { + return [pc.plain("/spoiler "), ...parseChildren(n, pc, opts)]; + } } } diff --git a/test/editor/deserialize-test.ts b/test/editor/deserialize-test.ts index 275f34ca8f1..0c6c8fcc398 100644 --- a/test/editor/deserialize-test.ts +++ b/test/editor/deserialize-test.ts @@ -98,6 +98,11 @@ describe("editor/deserialize", function () { expect(parts.length).toBe(1); expect(parts[0]).toStrictEqual({ type: "plain", text: "/me says DON'T SHOUT!" }); }); + it("spoiler", function () { + const parts = normalize(parseEvent(textMessage("/spoiler broiler"), createPartCreator())); + expect(parts.length).toBe(1); + expect(parts[0]).toStrictEqual({ type: "plain", text: "/spoiler broiler" }); + }); }); describe("html messages", function () { it("inline styling", function () { @@ -295,6 +300,11 @@ describe("editor/deserialize", function () { expect(parts.length).toBe(1); expect(parts[0]).toStrictEqual({ type: "plain", text: "/me says _DON'T SHOUT_!" }); }); + it("spoiler", function () { + const parts = normalize(parseEvent(htmlMessage("broiler"), createPartCreator())); + expect(parts.length).toBe(1); + expect(parts[0]).toStrictEqual({ type: "plain", text: "/spoiler broiler" }); + }); it("preserves nested quotes", () => { const html = "
foo
bar
"; const parts = normalize(parseEvent(htmlMessage(html), createPartCreator())); From fa50ee85118c1bdeaee39635b7d9d49fcff8f52d Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Thu, 26 Oct 2023 14:57:59 +0200 Subject: [PATCH 2/2] Appease the linter --- test/editor/deserialize-test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/editor/deserialize-test.ts b/test/editor/deserialize-test.ts index 0c6c8fcc398..2bd4925ec00 100644 --- a/test/editor/deserialize-test.ts +++ b/test/editor/deserialize-test.ts @@ -301,7 +301,9 @@ describe("editor/deserialize", function () { expect(parts[0]).toStrictEqual({ type: "plain", text: "/me says _DON'T SHOUT_!" }); }); it("spoiler", function () { - const parts = normalize(parseEvent(htmlMessage("broiler"), createPartCreator())); + const parts = normalize( + parseEvent(htmlMessage("broiler"), createPartCreator()), + ); expect(parts.length).toBe(1); expect(parts[0]).toStrictEqual({ type: "plain", text: "/spoiler broiler" }); });