diff --git a/gitnexus/src/core/wiki/html-viewer.ts b/gitnexus/src/core/wiki/html-viewer.ts
index 1e4ecabc9..8e5cb2786 100644
--- a/gitnexus/src/core/wiki/html-viewer.ts
+++ b/gitnexus/src/core/wiki/html-viewer.ts
@@ -68,9 +68,15 @@ function buildHTML(
meta: Record | null,
): string {
// Embed data as JSON inside the HTML
- const pagesJSON = JSON.stringify(pages);
- const treeJSON = JSON.stringify(moduleTree);
- const metaJSON = JSON.stringify(meta);
+ // Unicode-escape HTML-significant chars so the HTML parser can't misinterpret them
+ const safeJSON = (v: unknown) =>
+ JSON.stringify(v)
+ .replace(//g, '\\u003e')
+ .replace(/&/g, '\\u0026');
+ const pagesJSON = safeJSON(pages);
+ const treeJSON = safeJSON(moduleTree);
+ const metaJSON = safeJSON(meta);
const parts: string[] = [];
@@ -80,6 +86,7 @@ function buildHTML(
parts.push('');
parts.push('');
parts.push('');
+ parts.push('');
parts.push('' + esc(projectName) + ' — Wiki');
parts.push('