Skip to content

@beoe/rehype-graphviz

Rehype plugin to generate Graphviz diagrams in place of code fences. Example:

02SS(B)1SS(S)3486S(b)5S(a)S(A)SS(b)SS(a)S($end)S(b)S(a)S(a)7S(b)S(b)S(a)

Installation

Terminal window
npm i @beoe/rehype-graphviz

Usage

import rehypeGraphviz from "@beoe/rehype-graphviz";
const html = await unified()
.use(remarkParse)
.use(remarkRehype)
.use(rehypeGraphviz, {
/* options */
})
.use(rehypeStringify)
.process(`markdown`);

Check out other options.

Configuration

You probaly want to use inline strategy and implement dark scheme via CSS:

.graphviz {
text {
fill: var(--sl-color-white);
}
[fill="black"],
[fill="#000"] {
fill: var(--sl-color-white);
}
[stroke="black"],
[stroke="#000"] {
stroke: var(--sl-color-white);
}
}

Tips

inline strategy allows to use interactivity.

Transparent background

To remove background use:

```dot
digraph G {
bgcolor="transparent"
}
```

TODO

  • support images

    graphviz.neato('digraph { a[image="./resources/hpcc-logo.png"]; }', "svg", {
    images: [
    { path: "./resources/hpcc-logo.png", width: "272px", height: "92px" },
    ],
    });