inline code syntax highlighting: marpit custom engine + css
This commit is contained in:
21
marp.config.js
Normal file
21
marp.config.js
Normal 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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user