fix(publisher): derive KaTeX CSS version from the installed package
Browse filesA stale pinned URL plus integrity hash made browsers drop the stylesheet, so published equations fell back to raw MathML.
Co-authored-by: Cursor <cursoragent@cursor.com>
backend/src/publisher/html-renderer.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
| 5 |
* with SEO tags, dark/light theming, and minimal inline JS.
|
| 6 |
*/
|
| 7 |
|
|
|
|
| 8 |
import { generateHTML } from "@tiptap/html";
|
| 9 |
import { parseHTML } from "linkedom";
|
| 10 |
import { getServerExtensions } from "./extensions.js";
|
|
@@ -12,6 +13,15 @@ import type { PublishCSS } from "./index.js";
|
|
| 12 |
import { oklchFromHue } from "../shared/theme.js";
|
| 13 |
import { transformers, buildEmbedSrcdoc, type TransformContext } from "./transformers/index.js";
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
export interface PublishAuthor {
|
| 16 |
name: string;
|
| 17 |
url?: string;
|
|
@@ -133,9 +143,12 @@ export async function renderArticleHTML(
|
|
| 133 |
<meta name="twitter:description" content="${safeDesc}">
|
| 134 |
${meta.ogImage ? `<meta name="twitter:image" content="${escapeHtml(meta.ogImage)}">` : ""}
|
| 135 |
|
| 136 |
-
<!-- KaTeX CSS (version
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
| 139 |
crossorigin="anonymous">
|
| 140 |
|
| 141 |
<!-- Code blocks are pre-highlighted at publish time with Shiki (dual-theme
|
|
|
|
| 5 |
* with SEO tags, dark/light theming, and minimal inline JS.
|
| 6 |
*/
|
| 7 |
|
| 8 |
+
import { createRequire } from "node:module";
|
| 9 |
import { generateHTML } from "@tiptap/html";
|
| 10 |
import { parseHTML } from "linkedom";
|
| 11 |
import { getServerExtensions } from "./extensions.js";
|
|
|
|
| 13 |
import { oklchFromHue } from "../shared/theme.js";
|
| 14 |
import { transformers, buildEmbedSrcdoc, type TransformContext } from "./transformers/index.js";
|
| 15 |
|
| 16 |
+
// KaTeX CSS version must match the katex npm package that renders the
|
| 17 |
+
// math server-side (see transformers/math.ts), otherwise class names
|
| 18 |
+
// and metrics can drift. Derive it from the installed package instead
|
| 19 |
+
// of hardcoding: a stale pinned URL + integrity hash once made the
|
| 20 |
+
// browser reject the stylesheet entirely, so published equations fell
|
| 21 |
+
// back to raw MathML text with a full-width sqrt overline.
|
| 22 |
+
const require = createRequire(import.meta.url);
|
| 23 |
+
const KATEX_VERSION: string = require("katex/package.json").version;
|
| 24 |
+
|
| 25 |
export interface PublishAuthor {
|
| 26 |
name: string;
|
| 27 |
url?: string;
|
|
|
|
| 143 |
<meta name="twitter:description" content="${safeDesc}">
|
| 144 |
${meta.ogImage ? `<meta name="twitter:image" content="${escapeHtml(meta.ogImage)}">` : ""}
|
| 145 |
|
| 146 |
+
<!-- KaTeX CSS (version derived from the katex package used server-side
|
| 147 |
+
in the math transformer). No integrity attribute on purpose: the
|
| 148 |
+
hash has to be regenerated on every katex bump and a mismatch makes
|
| 149 |
+
the browser silently drop the stylesheet, which is far worse than
|
| 150 |
+
the marginal SRI benefit on a version-pinned jsdelivr URL. -->
|
| 151 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@${KATEX_VERSION}/dist/katex.min.css"
|
| 152 |
crossorigin="anonymous">
|
| 153 |
|
| 154 |
<!-- Code blocks are pre-highlighted at publish time with Shiki (dual-theme
|
backend/tests/__snapshots__/html-renderer-snapshot.test.ts.snap
CHANGED
|
@@ -61,9 +61,12 @@ exports[`snapshot - full render > matches snapshot for a typical article 1`] = `
|
|
| 61 |
<meta name="twitter:description" content="A test article">
|
| 62 |
|
| 63 |
|
| 64 |
-
<!-- KaTeX CSS (version
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
| 67 |
crossorigin="anonymous">
|
| 68 |
|
| 69 |
<!-- Code blocks are pre-highlighted at publish time with Shiki (dual-theme
|
|
|
|
| 61 |
<meta name="twitter:description" content="A test article">
|
| 62 |
|
| 63 |
|
| 64 |
+
<!-- KaTeX CSS (version derived from the katex package used server-side
|
| 65 |
+
in the math transformer). No integrity attribute on purpose: the
|
| 66 |
+
hash has to be regenerated on every katex bump and a mismatch makes
|
| 67 |
+
the browser silently drop the stylesheet, which is far worse than
|
| 68 |
+
the marginal SRI benefit on a version-pinned jsdelivr URL. -->
|
| 69 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.47/dist/katex.min.css"
|
| 70 |
crossorigin="anonymous">
|
| 71 |
|
| 72 |
<!-- Code blocks are pre-highlighted at publish time with Shiki (dual-theme
|