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:
Mario Zechner 2026-01-01 21:42:18 +01:00
parent cafbca02f9
commit 0ec8509de3
3 changed files with 3291 additions and 8 deletions

View file

@ -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 `<pre><code class="hljs">${highlighted}</code></pre>`;
}
return escapeHtml(code);
}
});