1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-31 13:44:28 +03:00

Switch from cheerio to DOMParser (#10929)

* Add tests around feature_latex_maths

* Switch from cheerio to DOMParser

* strict

* Iterate
This commit is contained in:
Michael Telatynski
2023-05-23 14:31:05 +01:00
committed by GitHub
parent 151b0efe73
commit 72d1bd910a
7 changed files with 98 additions and 99 deletions

View File

@ -17,6 +17,7 @@ limitations under the License.
import EditorModel from "../../src/editor/model";
import { htmlSerializeIfNeeded } from "../../src/editor/serialize";
import { createPartCreator } from "./mock";
import SettingsStore from "../../src/settings/SettingsStore";
describe("editor/serialize", function () {
describe("with markdown", function () {
@ -75,6 +76,7 @@ describe("editor/serialize", function () {
expect(html).toBe("*hello* world < hey world!");
});
});
describe("with plaintext", function () {
it("markdown remains plaintext", function () {
const pc = createPartCreator();
@ -102,4 +104,42 @@ describe("editor/serialize", function () {
expect(html).toBe("hello world");
});
});
describe("feature_latex_maths", () => {
beforeEach(() => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((feature) => feature === "feature_latex_maths");
});
it("should support inline katex", () => {
const pc = createPartCreator();
const model = new EditorModel([pc.plain("hello $\\xi$ world")], pc);
const html = htmlSerializeIfNeeded(model, {});
expect(html).toMatchInlineSnapshot(`"hello <span data-mx-maths="\\xi"><code>\\xi</code></span> world"`);
});
it("should support block katex", () => {
const pc = createPartCreator();
const model = new EditorModel([pc.plain("hello \n$$\\xi$$\n world")], pc);
const html = htmlSerializeIfNeeded(model, {});
expect(html).toMatchInlineSnapshot(`
"<p>hello</p>
<div data-mx-maths="\\xi"><code>\\xi</code></div>
<p>world</p>
"
`);
});
it("should not mangle code blocks", () => {
const pc = createPartCreator();
const model = new EditorModel([pc.plain("hello\n```\n$\\xi$\n```\nworld")], pc);
const html = htmlSerializeIfNeeded(model, {});
expect(html).toMatchInlineSnapshot(`
"<p>hello</p>
<pre><code>$\\xi$
</code></pre>
<p>world</p>
"
`);
});
});
});