mrueg / mermaid.go

A bridge of mermaid.js in golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mermaid.go

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)

How to build

  1. Checkout the code base git clone https://github.com/dreampuf/mermaid.go.git
  2. Fetch the latest version of mermaid.js
    curl -LO https://unpkg.com/mermaid/dist/mermaid.min.js
  3. Test it
    go test ./...

License

About

A bridge of mermaid.js in golang

License:MIT License


Languages

Language:Go 100.0%