-
It is not clear how to add the custom directive code in this page https://marpit.marp.app/directives?id=custom-directives |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
The example code is assuming to have import { Marpit } from '@marp-team/marpit'
const marpit = new Marpit()
// Define $theme global directive for aliasing to theme directive
marpit.customDirectives.global.$theme = (value) => {
return { theme: value }
}
// Define colorPreset local directive for setting multiple local directives at once
marpit.customDirectives.local.colorPreset = (value) => {
switch (value) {
case 'sunset':
return { backgroundColor: '#e62e00', color: '#fffff2' }
case 'dark':
return { backgroundColor: '#303033', color: '#f8f8ff' }
default:
return {}
}
}
// Render Markdown, and use the result as you like :)
const { html, css } = marpit.render(`
<!-- $theme: foobar -->
<!-- colorPreset: sunset -->
...
`) |
Beta Was this translation helpful? Give feedback.
-
I'm struggling to understand this example. I'm running marp-cli to create HTML slides from my markdown file. My understanding so far is, that marp-cli will by default use the Marp-Core as engine. Is there a way to extend this engine by custom directives? |
Beta Was this translation helpful? Give feedback.
The example code is assuming to have
marpit
instance. This is a full example: