| 1 | import { defineCodeblockTransformer } from '@slidev/types' |
| 2 | import { encode as encodePlantUml } from 'plantuml-encoder' |
| 3 | |
| 4 | const RE_PLANT_UML = /^plantuml\s*(\{[^\n]*\})?/ |
| 5 | |
| 6 | export default defineCodeblockTransformer(async ({ info, code, options: { data: { config: { plantUmlServer } } } }) => { |
| 7 | const match = info.match(RE_PLANT_UML) |
| 8 | if (!match) |
| 9 | return |
| 10 | const [, options] = match |
| 11 | const optionsProp = options ? `v-bind="${options}"` : '' |
| 12 | const encoded = encodePlantUml(code.trim()) |
| 13 | const serverProp = plantUmlServer === undefined ? '' : ` server=${JSON.stringify(plantUmlServer)}` |
| 14 | return `<PlantUml ${optionsProp} code="${encoded}"${serverProp} />` |
| 15 | }) |
| 16 |