21 lines
648 B
JavaScript
21 lines
648 B
JavaScript
import { Marp } from '@marp-team/marp-core'
|
|
|
|
// Custom Marp engine with Mermaid support via HTML injection
|
|
export default {
|
|
html: true,
|
|
engine: (constructorOptions) => {
|
|
const marp = new Marp(constructorOptions)
|
|
|
|
// Transform mermaid code blocks to divs that mermaid.js can render
|
|
const { code } = marp.markdown.renderer.rules
|
|
marp.markdown.renderer.rules.code = (tokens, idx, options, env, self) => {
|
|
const token = tokens[idx]
|
|
if (token.info.trim() === 'mermaid') {
|
|
return `<div class="mermaid">${token.content}</div>`
|
|
}
|
|
return code(tokens, idx, options, env, self)
|
|
}
|
|
|
|
return marp
|
|
}
|
|
}
|