-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
43 lines (33 loc) · 771 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"context"
"os"
"github.com/dreampuf/mermaid.go"
)
func main() {
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, _, _ := re.RenderAsPng(content)
scaled_png_in_bytes, _, _ := re.RenderAsScaledPng(content, 2.0)
err := os.WriteFile("example.svg", []byte(svg_content), 0644)
if err != nil {
os.Exit(1)
}
err = os.WriteFile("example.png", png_in_bytes, 0644)
if err != nil {
os.Exit(1)
}
err = os.WriteFile("example_scaled.png", scaled_png_in_bytes, 0644)
if err != nil {
os.Exit(1)
}
}