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

Deserialise spoilers back into slash command form #11805

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions src/editor/deserialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions test/editor/deserialize-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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("<span data-mx-spoiler>broiler</span>"), createPartCreator()));
expect(parts.length).toBe(1);
expect(parts[0]).toStrictEqual({ type: "plain", text: "/spoiler broiler" });
});
it("preserves nested quotes", () => {
const html = "<blockquote>foo<blockquote>bar</blockquote></blockquote>";
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
Expand Down
Loading