#graphviz #book #add

app mdbook-graphviz

mdbook preprocessor to add graphviz support

12 releases

0.2.1 Aug 10, 2024
0.2.0 May 1, 2024
0.1.7 Apr 9, 2024
0.1.6 Feb 10, 2023
0.0.1 Nov 1, 2019

#114 in Text processing

Download history 611/week @ 2024-07-20 719/week @ 2024-07-27 527/week @ 2024-08-03 686/week @ 2024-08-10 562/week @ 2024-08-17 559/week @ 2024-08-24 526/week @ 2024-08-31 461/week @ 2024-09-07 571/week @ 2024-09-14 627/week @ 2024-09-21 558/week @ 2024-09-28 552/week @ 2024-10-05 523/week @ 2024-10-12 505/week @ 2024-10-19 468/week @ 2024-10-26 548/week @ 2024-11-02

2,125 downloads per month

MPL-2.0 license

35KB
843 lines

mdBook Graphviz

crates.io LICENSE

Install

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

Usage

Just dot is supported, but any of the other graphviz tools would be easy to add.

Mark A dot Code Block For Processing

Input

```dot process
digraph {
    "processed" -> "graph"
}
```

Output

<div class="mdbook-graphviz-output"><svg>...</svg></div>

The class attribute gives you the chance to apply a common style to all the output images (e.g. center all of them).

Rendered

dot Code Blocks Without The process Flag Are Ignored

Input

```dot
digraph {
    "processed" -> "graph"
}
```

Output

```dot
digraph {
    "processed" -> "graph"
}
```

Output To File

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

.gitignore

This .gitignore should cover the generated SVG files.

*.generated.svg

When using output-to-file, links can be added to the images via the link-to-file flag:

[preprocessor.graphviz]
output-to-file = true
link-to-file = true

or

MDBOOK_preprocessor__graphviz__output_to_file="true" MDBOOK_preprocessor__graphviz__link_to_file="true" mdbook build

Embedding dot files

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"]

Overriding the info-string

Some tools prefer a specific annotation for dot/graphviz diagrams. For compatability with these tools mdbook-graphviz can support a custom value for marking diagrams it should process. This is via the info-string flag:

[preprocessor.graphviz]
info-string = "graphviz"

or

MDBOOK_preprocessor__graphviz__info_string="graphviz" mdbook build

More information about preprocessors and ordering can be found here.

Dependencies

~16–28MB
~425K SLoC