#mdbook #markdown #svg #svgbob

bin+lib mdbook-svgbob2

Alternative mdbook preprocessor for svgbob

6 releases

0.2.3 Dec 11, 2021
0.2.2 Sep 28, 2021
0.1.1 Sep 28, 2021

#363 in Text processing

MIT license

163 lines

Alternative svgbob preprocessor for mdbook

Crates.io GitHub last commit License

A preprocessor for mdbook to convert svgbob codeblocks into nice SVG images using svgbob.

This crate serves as an alternative to mdbook-svgbob which was a big inspiration while writing the code for this crate.

The reason why I created this was that the original uses outdated dependencies and seems to break tables some reason, and it requires the source to have Unix line endings as it breaks with Windows line endings. I also wanted to learn how to write mdbook preprocessors and had a usecase for an updated svgbob integration.


Install with cargo:

cargo install mdbook-svgbob2

Or to install from the git mirror:

cargo install --git https://github.com/Treeniks/mdbook-svgbob2.git


Add this to your cargo.toml:


Optionally add any arguments for the svgbob settings:

font_size = "14"
font_family = "monospace"
fill_color = "black"
background = "transparent"
stroke_color = "var(--fg)" # variable from the mdbook css files
stroke_width = "2.0"
scale = "8.0"
enhance_circuitries = "true"
include_backdrop = "true"
include_styles = "true"
include_defs = "true"
merge_line_with_shapes = "false"

# this is a non-svgbob custom setting
font_color = "var(--fg)"

The above are the default settings. Most of them are the svgbob defaults, with the exception of background and stroke_color which I have changed to better fit mdbook.
svgbob currently does not support changing the font color (although there are feature requests for this to be added), and because a pure black font color doesn't work well with different mdbook themes, I added the ability to change the font color.

Then simply include svgbob codeblocks in some chapter:

   .-/ / /->
  ( *  \/
   '-.  \
      \ /

and it should display as a nicely rendered svg when rendered with mdbook.


  • there are currently no tests implemented
  • 2 consecutive svgbob blocks will currently break the second one
    this is fixed by having anything else written between the two blocks


~286K SLoC