mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 01:01:42 +00:00
Fix markdown code block syntax highlighting
Marked v15 removed the highlight option from setOptions. Use marked.use() with a custom renderer instead.
This commit is contained in:
parent
cafbca02f9
commit
0ec8509de3
3 changed files with 3291 additions and 8 deletions
11
.pi/hooks/status-demo.ts
Normal file
11
.pi/hooks/status-demo.ts
Normal file
|
|
@ -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");
|
||||||
|
});
|
||||||
|
}
|
||||||
3263
out.html
Normal file
3263
out.html
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -1058,17 +1058,26 @@
|
||||||
return marked.parse(escaped);
|
return marked.parse(escaped);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure marked
|
// Configure marked with syntax highlighting
|
||||||
marked.setOptions({
|
marked.use({
|
||||||
breaks: true,
|
breaks: true,
|
||||||
gfm: true,
|
gfm: true,
|
||||||
highlight: function(code, lang) {
|
renderer: {
|
||||||
if (lang && hljs.getLanguage(lang)) {
|
code(token) {
|
||||||
try {
|
const code = token.text;
|
||||||
return hljs.highlight(code, { language: lang }).value;
|
const lang = token.lang;
|
||||||
} catch {}
|
let highlighted;
|
||||||
|
if (lang && hljs.getLanguage(lang)) {
|
||||||
|
try {
|
||||||
|
highlighted = hljs.highlight(code, { language: lang }).value;
|
||||||
|
} catch {
|
||||||
|
highlighted = escapeHtml(code);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
highlighted = escapeHtml(code);
|
||||||
|
}
|
||||||
|
return `<pre><code class="hljs">${highlighted}</code></pre>`;
|
||||||
}
|
}
|
||||||
return escapeHtml(code);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue