| 1 | import { defineCodeblockTransformer } from '@slidev/types' |
| 2 | import lz from 'lz-string' |
| 3 | |
| 4 | const RE_MERMAID = /^mermaid\s*(\{[^\n]*\})?/ |
| 5 | |
| 6 | export default defineCodeblockTransformer(async ({ info, code }) => { |
| 7 | const match = info.match(RE_MERMAID) |
| 8 | if (!match) |
| 9 | return |
| 10 | const [, options] = match |
| 11 | const optionsProp = options ? `v-bind="${options}"` : '' |
| 12 | const encoded = lz.compressToBase64(code.trim()) |
| 13 | return `<Mermaid ${optionsProp} code-lz="${encoded}" />` |
| 14 | }) |
| 15 |