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:
ts
import type { MarkdownTransformContext } from '@slidev/types'
import { defineTransformersSetup } from '@slidev/types'
function myCodeblock(ctx: MarkdownTransformContext) {
console.log('index in presentation', ctx.slide.index)
ctx.s.replace(
/^```myblock *(\{[^\n]*\})?\n([\s\S]+?)\n```/gm,
(full, options = '', code = '') => {
return `...`
},
)
}
export default defineTransformersSetup(() => {
return {
pre: [],
preCodeblock: [myCodeblock],
postCodeblock: [],
post: [],
}
})The return value should be the custom options for the transformers. The pre, preCodeblock, postCodeblock, and post are arrays of functions that will be called in order to transform the markdown content. The order of the transformers is:
prefrom your projectprefrom addons and themes- Import snippets syntax and Shiki magic move
preCodeblockfrom your projectpreCodeblockfrom addons and themes- Built-in special code blocks like Mermaid, Monaco and PlantUML
postCodeblockfrom addons and themespostCodeblockfrom your project- Other built-in transformers like code block wrapping
postfrom addons and themespostfrom your project