inline code syntax highlighting: marpit custom engine + css

This commit is contained in:
2026-04-22 13:15:19 +02:00
parent 79aaa14c29
commit 2680a745cf
5 changed files with 1966 additions and 7 deletions

21
marp.config.js Normal file
View File

@@ -0,0 +1,21 @@
const { Marp } = require('@marp-team/marp-core');
const hljs = require('highlight.js');
module.exports = {
engine: (opts) => {
const marp = new Marp(opts);
const md = marp.markdown;
const defaultInline = md.renderer.rules.code_inline
|| ((tokens, idx, options, env, self) => `<code>${md.utils.escapeHtml(tokens[idx].content)}</code>`);
md.renderer.rules.code_inline = (tokens, idx, options, env, self) => {
const content = tokens[idx].content;
try {
const highlighted = hljs.highlight(content, { language: 'html', ignoreIllegals: true }).value;
return `<code class="hljs language-html">${highlighted}</code>`;
} catch (e) {
return defaultInline(tokens, idx, options, env, self);
}
};
return marp;
}
};