22 lines
785 B
JavaScript
22 lines
785 B
JavaScript
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;
|
|
}
|
|
};
|