https://github.com/rigtorp/goldmark-graphviz
Goldmark extension to render Graphviz figures without cgo or external dependencies
https://github.com/rigtorp/goldmark-graphviz
Last synced: over 1 year ago
JSON representation
Goldmark extension to render Graphviz figures without cgo or external dependencies
- Host: GitHub
- URL: https://github.com/rigtorp/goldmark-graphviz
- Owner: rigtorp
- License: mit
- Created: 2023-01-29T05:25:06.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-29T05:37:12.000Z (over 3 years ago)
- Last Synced: 2025-04-01T17:17:02.676Z (over 1 year ago)
- Language: Go
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Graphviz for Goldmark
This is an extension for [Goldmark](https://github.com/yuin/goldmark) that adds
support for generating figures using [Graphviz](https://graphviz.org/). It
doesn't rely on cgo or an external binary, instead using the
[wazero](https://wazero.io/) WebAssembly runtime to embed Graphviz.
## Usage
Register the extension:
``` go
goldmark.New(
goldmark.WithExtensions(&graphviz.Extender{}),
).Convert(src, dst)
```
Fenced code blocks like below will now be rendered using Graphviz:
~~~markdown
```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](https://github.com/rigtorp/go-graphviz) package. For a small
Graphviz graph, go-graphviz takes about 51ms:
```shell
$ 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](https://github.com/jchenry/goldmark-pikchr) extension by
[Colin Henry](https://github.com/jchenry) and the
[goldmark-d2](https://github.com/FurqanSoftware/goldmark-d2) extension by
[Furqan Software](https://github.com/FurqanSoftware).