diff --git a/.claude/skills/verify-outline/journeys/export-html.mjs b/.claude/skills/verify-outline/journeys/export-html.mjs new file mode 100644 index 0000000000..a6941c7a20 --- /dev/null +++ b/.claude/skills/verify-outline/journeys/export-html.mjs @@ -0,0 +1,42 @@ +// Download a document as HTML through "Document options" → Export → HTML, +// then open the downloaded file and screenshot it. +// Args: doc= (path such as /doc/, required), expect= (text in the file). +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +export default async ({ page, context, click, step, args, log }) => { + if (!args.doc) { + throw new Error("doc= is required"); + } + await page.goto(args.doc); + await page.waitForLoadState("networkidle"); + await click(page.getByRole("button", { name: "Document options" })); + await click(page.getByRole("menuitem", { name: "Export" })); + const htmlItem = page.getByRole("menu", { name: "Export" }).getByRole("menuitem", { name: /^HTML/ }); + await htmlItem.waitFor(); + await step("export-menu"); + const [download] = await Promise.all([ + page.waitForEvent("download"), + // A pointer move to the submenu crosses "Copy" and closes it, so use the keyboard. + htmlItem.focus().then(() => page.keyboard.press("Enter")), + ]); + const file = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "outline-export-")), download.suggestedFilename()); + await download.saveAs(file); + const html = fs.readFileSync(file, "utf8"); + const stylesheet = html.match(/https:\/\/cdn\.jsdelivr\.net\/npm\/katex@[^"]+/)?.[0]; + log("file:", file, "stylesheet:", stylesheet); + if (args.expect && !html.includes(args.expect)) { + throw new Error(`downloaded HTML does not include ${JSON.stringify(args.expect)}`); + } + + const view = await context.newPage(); + await view.goto(`file://${file}`, { waitUntil: "networkidle" }); + await view.evaluate(() => document.fonts.ready); + const errors = await view.locator(".katex-error").count(); + if (errors !== 0) { + throw new Error(`${errors} KaTeX error nodes in export`); + } + await step("downloaded-html", view); + return { file, stylesheet }; +}; diff --git a/package.json b/package.json index 65b787fd79..bdfbfb9139 100644 --- a/package.json +++ b/package.json @@ -145,7 +145,7 @@ "js.foresight": "^4.2.1", "jsdom": "^30.1.3", "jsonwebtoken": "^9.0.3", - "katex": "^0.18.2", + "katex": "^0.19.1", "kbar": "^1.0.0", "koa": "^3.3.0", "koa-body": "^8.0.1", diff --git a/server/models/helpers/DocumentHelper.test.ts b/server/models/helpers/DocumentHelper.test.ts index 4e254bcd79..1450ed7176 100644 --- a/server/models/helpers/DocumentHelper.test.ts +++ b/server/models/helpers/DocumentHelper.test.ts @@ -1,3 +1,4 @@ +import { version as katexVersion } from "katex"; import Revision from "@server/models/Revision"; import { buildCollection, buildDocument } from "@server/test/factories"; import { ChangesetHelper } from "@shared/editor/lib/ChangesetHelper"; @@ -254,7 +255,7 @@ describe("DocumentHelper", () => { }); const result = await DocumentHelper.toHTML(document); expect(result).toContain('class="katex"'); - expect(result).toContain("katex.min.css"); + expect(result).toContain(`katex@${katexVersion}/dist/katex.min.css`); }); it("should not include the KaTeX stylesheet without math", async () => { diff --git a/server/models/helpers/ProsemirrorHelper.tsx b/server/models/helpers/ProsemirrorHelper.tsx index f17755ae69..690f19ef1e 100644 --- a/server/models/helpers/ProsemirrorHelper.tsx +++ b/server/models/helpers/ProsemirrorHelper.tsx @@ -4,6 +4,7 @@ import emojiRegex from "emoji-regex"; import type { JSDOM } from "jsdom"; import { chunk } from "es-toolkit/compat"; import ukkonen from "ukkonen"; +import { version as katexVersion } from "katex"; import { EditorState, type Plugin } from "prosemirror-state"; import { DecorationSet, @@ -114,8 +115,7 @@ class NoopResizeObserver implements ResizeObserver { // KaTeX renders math server-side during HTML export, but relies on this // stylesheet (loaded dynamically in the app) to position glyphs correctly. -const katexStylesheetUrl = - "https://cdn.jsdelivr.net/npm/katex@0.16.45/dist/katex.min.css"; +const katexStylesheetUrl = `https://cdn.jsdelivr.net/npm/katex@${katexVersion}/dist/katex.min.css`; function isDecorationSource(value: unknown): value is DecorationSource { if (typeof value !== "object" || value === null) { diff --git a/yarn.lock b/yarn.lock index d451da3b54..2cd6d18241 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8867,6 +8867,13 @@ __metadata: languageName: node linkType: hard +"commander@npm:^15.0.0": + version: 15.1.0 + resolution: "commander@npm:15.1.0" + checksum: 10c0/dd1013291d3e8779c726313616fa23174abc962182d0894ac73017c55d8b1ffe4a72401d91a1173974050536576896dc5279db07d37f929dbad469a16a12c54e + languageName: node + linkType: hard + "commander@npm:^2.20.0": version: 2.20.3 resolution: "commander@npm:2.20.3" @@ -12585,14 +12592,14 @@ __metadata: languageName: node linkType: hard -"katex@npm:^0.18.2": - version: 0.18.2 - resolution: "katex@npm:0.18.2" +"katex@npm:^0.19.1": + version: 0.19.1 + resolution: "katex@npm:0.19.1" dependencies: - commander: "npm:^8.3.0" + commander: "npm:^15.0.0" bin: katex: cli.js - checksum: 10c0/05f0eadc718cbf18d805089cfe7d930f15199b2781087f2055b25f93b0adaad5cfa7c50311366ced324e85f382edae7ed20ba09819ff8eab62b96bba5fe97029 + checksum: 10c0/20ceeefe75b852acfb1739aa1fe64322acee332cdd7ccefb6e952285c27201ccfb92c65afb38d555d53a41756fba77b7cd60462f8cfce7323a3902ef2e57ad91 languageName: node linkType: hard @@ -14489,7 +14496,7 @@ __metadata: js.foresight: "npm:^4.2.1" jsdom: "npm:^30.1.3" jsonwebtoken: "npm:^9.0.3" - katex: "npm:^0.18.2" + katex: "npm:^0.19.1" kbar: "npm:^1.0.0" koa: "npm:^3.3.0" koa-body: "npm:^8.0.1"