Skip to content

How to access frontmatter data (as title, author...) from a plugin ? #550

Closed Answered by yhatt
Welsh44 asked this question in Q&A
Discussion options

You must be logged in to vote

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.

// 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' &&
          t…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by yhatt
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants