-
Hi I discovered Marp few weeks ago and found it very convenient. As I 'm working on template for my company, I'd like to implement a canvas. Thanks in advance for any clue. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
As mentioned at https://marpit.marp.app/directives and https://github.com/orgs/marp-team/discussions/510#discussioncomment-9397590, Marpit framework will store parsed directives, including defined in the front-matter, as the metadata of each slide token: // engine.mjs
const yourPlugin = (md) => {
md.core.ruler.after(
'marpit_directives_apply',
'your_custom_rule', // Rename the rule as you like
(state) => {
if (state.inlineMode) return
for (const token of state.tokens) {
if (
typeof token.meta?.marpitSlide === 'number' &&
typeof token.meta.marpitDirectives === 'object'
) {
// Peak the metadata of directives for debug
console.log(
token.meta?.marpitSlide, // Slide page index (0-based)
'=>',
token.meta.marpitDirectives // Directives of the slide
)
// ... and you can do anything with using the value of directives ...
}
}
}
)
}
export default ({ marp }) => marp.use(yourPlugin) ---
title: Title
author: Author
header: '**Header**'
footer: '_Footer_'
---
# Title
---
<!-- footer: Footer changed -->
Hello! $ marp --engine ./engine.mjs ./markdown.md
[ INFO ] Converting 1 markdown...
0 => {
header: '**Header**',
footer: '_Footer_',
marpCLITitle: 'Title',
marpCLIAuthor: 'Author'
}
1 => {
header: '**Header**',
footer: 'Footer changed',
marpCLITitle: 'Title',
marpCLIAuthor: 'Author'
}
[ INFO ] markdown.md => markdown.html Note The name of directive and the identifier of metadata may become different, for a reason of the purpose to avoid conflict identifiers with other plugins. Some of well-known global directives such as |
Beta Was this translation helpful? Give feedback.
-
Thank you. |
Beta Was this translation helpful? Give feedback.
As mentioned at https://marpit.marp.app/directives and https://github.com/orgs/marp-team/discussions/510#discussioncomment-9397590, Marpit framework will store parsed directives, including defined in the front-matter, as the metadata of each slide token:
marpitDirectives
. You can inject the parser rule of markdown-it to read the metadata at after parsing directives.