Skip to content

Where should I add the code for a custom directive? #319

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

You must be logged in to vote

Marpit instance has customDirectives.global and customDirectives.local object to allow adding directives as you like.

The example code is assuming to have marpit instance. This is a full example:

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 { backg…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@vmgustavo
Comment options

@yhatt
Comment options

Answer selected by yhatt
Comment options

You must be logged in to vote
2 replies
@yhatt
Comment options

@OlegHahm
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants