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:
pre
from your projectpre
from addons and themes- Import snippets syntax and Shiki magic move
preCodeblock
from your projectpreCodeblock
from addons and themes- Built-in special code blocks like Mermaid, Monaco and PlantUML
postCodeblock
from addons and themespostCodeblock
from your project- Other built-in transformers like code block wrapping
post
from addons and themespost
from your project