Skip to content

Having an alternating style for odd or even pages #456

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

You must be logged in to vote

Marp is designed for PowerPoint style presentation slides, and is not supported the book style pagination.

If necessary, you can write a Marp (Marpit) plugin to add odd or even class to the <section> element, and use it in Marp CLI.

// engine.mjs
const marpOddEvenSlidePlugin = (md) => {
  md.core.ruler.after('marpit_slide', 'marp_odd_even_slide', (state) => {
    if (state.inlineMode) return

    for (const token of state.tokens) {
      if (token.type === 'marpit_slide_open') {
        const pageNumber = token.meta.marpitSlide + 1
        token.attrJoin('class', pageNumber % 2 === 0 ? 'even' : 'odd')
      }
    }
  })
}

export default ({ marp }) => marp.use(marpOddEvenSlidePlugin)
marp…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by yhatt
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