mermaid.go is a library for invoking mermaid.js and getting rending result.
sequenceDiagram
Actor A as User
participant B as mermaid.go
participant C as chromedp
A ->>+ B: NewRenderEngine()
B ->>+ C: Lanch new instance of chrome and eval JS library
C -->> B:
B -->> A:
loop Render Process
A ->> B: Render()
B ->> C: mermaid.render()
C ->> B: { svg, boxModel, exceptions }
B ->> A: Result{ Svg, BoxModel Error }
end
A ->> B: Cancel()
B -->> C: Context done
C -->>- C: Shutdown chrome instance
B -->>- A:
Installation:
go get -u github.com/dreampuf/mermaid.go
Example:
ctx := context.Background()
re, _ := mermaid_go.NewRenderEngine(ctx)
defer re.Cancel()
content := `graph TD;
A-->B;
A-->C;
B-->D;
C-->D;`
// get the render result in SVG/XML string
svg_content, _ := re.Render(content)
// get the result as PNG bytes
png_in_bytes, box, _ := re.RenderAsPng(content)
- Checkout the code base
git clone https://github.com/dreampuf/mermaid.go.git
- Fetch the latest version of mermaid.js
curl -LO https://unpkg.com/mermaid/dist/mermaid.min.js
- Test it
go test ./...
- mermaid.go: MIT License
- mermaid.js: MIT License
- chromedp: MIT License