A preprocessor for mdbook to convert
d2
codeblocks into SVG images using
D2.
Install with cargo:
sh
cargo install mdbook-d2
Or to install from git:
sh
cargo install --git https://github.com/danieleades/mdbook-d2
This preprocessor assumes that D2
is installed locally and on the path. D2 installation instructions can be found here.
Check that the local installation is working correctly using
sh
d2 --version
Add this to your book.toml
:
```toml [preprocessor.d2]
path = "d2"
layout = "dagre"
inline = true
src/
for generated diagrams.output-dir = "d2" ```
Use in your 'book' by annotating D2 code blocks-
````md
```d2
hans: Hans Niemann
defendants: { mc: Magnus Carlsen playmagnus: Play Magnus Group chesscom: Chess.com naka: Hikaru Nakamura
mc -> playmagnus: Owns majority playmagnus <-> chesscom: Merger talks chesscom -> naka: Sponsoring }
hans -> defendants: 'sueing for $100M'
defendants.naka -> hans: Accused of cheating on his stream defendants.mc -> hans: Lost then withdrew with accusations defendants.chesscom -> hans: 72 page report of cheating ``` ````
The code block will be replaced with the D2 diagram in the rendered document.
The code in this preprocessor is based on that from https://github.com/matthiasbeyer/mdbook-svgbob2