Skip to content

Configure Transformers

Environment: node
This setup function will only run on Node.js environment, you can have access to Node's API.

This setup function allows you to define custom transformers for the markdown content of each slide. This is useful when you want to add custom Markdown syntax and render custom code blocks. To start, create a ./setup/transformers.ts file with the following content:

setup/transformers.ts
ts
import { , ,  } from '@slidev/types'
import  from 'lz-string'

const  = (() => {
  .('index in presentation', ..)
  ..(
    /^\[\[\[(.*)\]\]\]/gm,
    (, ) => {
      return `...`
    },
  )
})

const  = (() => {
  if (..('myblock')) {
    .('index in presentation', .?.)
    return `<MyBlockRenderer code="${.(.)}" />`
  }
})

export default (() => {
  return {
    // This applies before the Markdown is parsed, per slide
    : [],
    // This applies per Markdown code block
    : [],
  }
})

NOTE

When possible, implement pre transformers as markdown-it plugins for better robustness.

Released under the MIT License.