mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-25 23:00:32 +08:00
The sanitizer allowlist strips KaTeX's markup, and index.html never loaded katex.min.css, so math has only ever shown up as flat text. We now typeset math after sanitizing and load the stylesheet.
27 lines
887 B
TypeScript
27 lines
887 B
TypeScript
import { expect, test } from "vitest";
|
|
|
|
import { renderMarkdown } from "@app/lib/markdown";
|
|
|
|
// DOMPurify under happy-dom drops a document's first element, so each
|
|
// document starts with a paragraph that isn't under test.
|
|
function render(content: string): HTMLElement {
|
|
const element = document.createElement("div");
|
|
element.innerHTML = renderMarkdown(`intro\n\n${content}`);
|
|
return element;
|
|
}
|
|
|
|
test("renders inline math with KaTeX", () => {
|
|
const math = render("inline $3x^{-1}+(1+x)^2$ math").querySelector(
|
|
"p .katex",
|
|
);
|
|
expect(math?.querySelector(".katex-html")).not.toBeNull();
|
|
expect(math?.querySelector("annotation")?.textContent).toBe(
|
|
"3x^{-1}+(1+x)^2",
|
|
);
|
|
});
|
|
|
|
test("renders block math in display mode", () => {
|
|
const element = render("$$\n\\sum_{k=1}^n a_k\n$$\n");
|
|
expect(element.querySelector(".katex-display .katex-html")).not.toBeNull();
|
|
});
|