rigtorp / goldmark-graphviz

Goldmark extension to render Graphviz figures without cgo or external dependencies

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Graphviz for Goldmark

This is an extension for Goldmark that adds support for generating figures using Graphviz. It doesn't rely on cgo or an external binary, instead using the wazero WebAssembly runtime to embed Graphviz.

Usage

Register the extension:

goldmark.New(
	goldmark.WithExtensions(&graphviz.Extender{}),
).Convert(src, dst)

Fenced code blocks like below will now be rendered using Graphviz:

```graphviz
digraph D {

  A [shape=diamond]
  B [shape=box]
  C [shape=circle]

  A -> B [style=dashed, color=grey]
  A -> C [color="black:invis:black"]
  A -> D [penwidth=5, arrowhead=none]

}
```

Resulting in a figure like below:

Performance

Performance will be the same as for the underlying go-graphviz package. For a small Graphviz graph, go-graphviz takes about 51ms:

$ go test -test.bench .
goos: linux
goarch: amd64
pkg: github.com/rigtorp/go-graphviz
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
BenchmarkGraphviz-8           24          51285746 ns/op
PASS
ok      github.com/rigtorp/go-graphviz  3.057s

Acknowledgements

This extension is based on the goldmark-pikchr extension by Colin Henry and the goldmark-d2 extension by Furqan Software.

About

Goldmark extension to render Graphviz figures without cgo or external dependencies

License:MIT License


Languages

Language:Go 100.0%