headless-mermaid
Version:
A mermaid.js handler for server-side rendering.
30 lines (26 loc) • 711 B
JavaScript
const mermaid = require("."),
fs = require("fs")
let config = {
theme: "forest",
sequence: {
showSequenceNumbers: true,
},
},
code = `
sequenceDiagram
Alice ->> Bob: Hello Bob, how are you?
Bob-->>John: How about you John?
Bob--x Alice: I am good thanks!
Bob-x John: I am good thanks!
Note right of John: Bob thinks a long<br/>long time, so long<br/>that the text does<br/>not fit on a row.
Bob-->Alice: Checking with John...
Alice->John: Yes... John, how are you?`
// Use catch/rejection for error handling
mermaid
.execute(code, config)
.then((svg) => {
fs.writeFileSync("output.svg", svg)
})
.catch((error) => {
console.log(error)
})