cargo install mdbook-graphviz
Install Graphviz
brew install graphviz
book.toml
[preprocessor.graphviz]
command = "mdbook-graphviz"
output-to-file = false # defaults to false, change to true to create SVG files instead of rendering them inline
Just dot
is supported, but any of the other graphviz tools would be easy to add.
```dot process
digraph {
"processed" -> "graph"
}
```
<div><svg>...</svg></div>
```dot
digraph {
"processed" -> "graph"
}
```
```dot
digraph {
"processed" -> "graph"
}
```
The default is to embed the SVG as HTML in the Markdown, however if this causes problems or if the actual files are
needed you can disable this via the output-to-file
flag:
[preprocessor.graphviz]
output-to-file = true
or
MDBOOK_preprocessor__graphviz__output_to_file="true" mdbook build
This .gitignore
should cover the generated SVG files.
*.generated.svg
Sometimes you don't want to write dot code, but instead include it from a file:
```dot
{{#include path/to/file.dot}}
```
In this case, you might want to modify the order of preprocessors, so the include directives get resolved before it's passed to Graphviz.
In that case, make sure your [preprocessor.graphviz]
section in the config
orders itself after links
:
[preprocessor.graphviz]
after = ["links"]
More information about preprocessors and ordering can be found here.