Deserialise spoilers back into slash command form (#11805)
* Deserialise spoilers back into slash command form Fixes: vector-im/element-web#26344 * Appease the linter
This commit is contained in:
parent
b382a1c733
commit
c7c51d764f
2 changed files with 16 additions and 0 deletions
|
@ -247,6 +247,10 @@ function parseNode(n: Node, pc: PartCreator, opts: IParseOptions, mkListItem?: (
|
||||||
|
|
||||||
return pc.plainWithEmoji(`${delimLeft}${tex}${delimRight}`);
|
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)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,11 @@ describe("editor/deserialize", function () {
|
||||||
expect(parts.length).toBe(1);
|
expect(parts.length).toBe(1);
|
||||||
expect(parts[0]).toStrictEqual({ type: "plain", text: "/me says DON'T SHOUT!" });
|
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 () {
|
describe("html messages", function () {
|
||||||
it("inline styling", function () {
|
it("inline styling", function () {
|
||||||
|
@ -295,6 +300,13 @@ describe("editor/deserialize", function () {
|
||||||
expect(parts.length).toBe(1);
|
expect(parts.length).toBe(1);
|
||||||
expect(parts[0]).toStrictEqual({ type: "plain", text: "/me says _DON'T SHOUT_!" });
|
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", () => {
|
it("preserves nested quotes", () => {
|
||||||
const html = "<blockquote>foo<blockquote>bar</blockquote></blockquote>";
|
const html = "<blockquote>foo<blockquote>bar</blockquote></blockquote>";
|
||||||
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
|
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue