From 0ec8509de3cc679a4cec7c4ca89e439cf7a1b65e Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 1 Jan 2026 21:42:18 +0100 Subject: [PATCH] Fix markdown code block syntax highlighting Marked v15 removed the highlight option from setOptions. Use marked.use() with a custom renderer instead. --- .pi/hooks/status-demo.ts | 11 + out.html | 3263 +++++++++++++++++ .../src/core/export-html/template.js | 25 +- 3 files changed, 3291 insertions(+), 8 deletions(-) create mode 100644 .pi/hooks/status-demo.ts create mode 100644 out.html diff --git a/.pi/hooks/status-demo.ts b/.pi/hooks/status-demo.ts new file mode 100644 index 00000000..a9720f80 --- /dev/null +++ b/.pi/hooks/status-demo.ts @@ -0,0 +1,11 @@ +import type { HookAPI } from "@mariozechner/pi-coding-agent"; + +export default function (pi: HookAPI) { + pi.on("turn_start", async (_event, ctx) => { + ctx.ui.setStatus("demo", "๐Ÿ”„ Thinking..."); + }); + + pi.on("turn_end", async (_event, ctx) => { + ctx.ui.setStatus("demo", "โœ“ Ready"); + }); +} diff --git a/out.html b/out.html new file mode 100644 index 00000000..a48dacfa --- /dev/null +++ b/out.html @@ -0,0 +1,3263 @@ + + + + + + Session Export + + + + + +
+ +
+
+
+
+
+ +
+
+ + + + + + + + + + + + + diff --git a/packages/coding-agent/src/core/export-html/template.js b/packages/coding-agent/src/core/export-html/template.js index f0c1dd01..431ae495 100644 --- a/packages/coding-agent/src/core/export-html/template.js +++ b/packages/coding-agent/src/core/export-html/template.js @@ -1058,17 +1058,26 @@ return marked.parse(escaped); } - // Configure marked - marked.setOptions({ + // Configure marked with syntax highlighting + marked.use({ breaks: true, gfm: true, - highlight: function(code, lang) { - if (lang && hljs.getLanguage(lang)) { - try { - return hljs.highlight(code, { language: lang }).value; - } catch {} + renderer: { + code(token) { + const code = token.text; + const lang = token.lang; + let highlighted; + if (lang && hljs.getLanguage(lang)) { + try { + highlighted = hljs.highlight(code, { language: lang }).value; + } catch { + highlighted = escapeHtml(code); + } + } else { + highlighted = escapeHtml(code); + } + return `
${highlighted}
`; } - return escapeHtml(code); } });