Skip to main content

mkdocs-graphviz

mkdocs-graphviz renders Graphviz/DOT source to inline SVG at MkDocs build time.

Version 2.0.1 is a deliberately breaking redesign. It is a real MkDocs plugin, ships its own JavaScript/CSS runtime inside the Python wheel, supports native Light/Dark Graphviz rendering, and exposes Graphviz attributes without legacy shortcuts.

Installation

Install Graphviz with your operating system package manager, then install the plugin:

python -m pip install mkdocs-graphviz

For local development on an Arch Linux system using the system Python:

python -m pip install --break-system-packages -e .

Minimal MkDocs configuration

plugins:
  - search
  - mkdocs_graphviz:
      common:
        graph:
          bgcolor: "none"
      light:
        node:
          color: "#000000"
          fontcolor: "#000000"
        edge:
          color: "#000000"
          fontcolor: "#000000"
      dark:
        node:
          color: "#FFFFFF"
          fontcolor: "#FFFFFF"
        edge:
          color: "#FFFFFF"
          fontcolor: "#FFFFFF"

No extra_javascript, extra_css, CDN, or Markdown extension entry is required. The plugin injects its packaged minified runtime assets automatically.

There are no scope-less shortcuts in 2.0. Every native Graphviz attribute belongs explicitly to graph, node, or edge inside common, light, or dark.

Hex colors use Graphviz syntax and therefore keep the leading #. Quote them in YAML:

light:
  node:
    color: "#000000"

Markdown syntax

The default fence is intentionally simple:

```dot
digraph G {
    A -> B -> C
}
```

Fence words are data-driven aliases:

plugins:
  - mkdocs_graphviz:
      fences:
        dot: dot
        gv: dot
        neato: neato
        radial: twopi

The key is the Markdown fence word; the value is the Graphviz layout passed to dot -K....

Configuration inheritance

The effective configuration is resolved independently for Light and Dark:

Graphviz built-in defaults
        ↓
global common.graph/node/edge
        ↓
global light|dark.graph/node/edge
        ↓
page common.graph/node/edge
        ↓
page light|dark.graph/node/edge
        ↓
graph common.graph/node/edge
        ↓
graph light|dark.graph/node/edge
        ↓
explicit attributes in DOT source

Per-page

Use normal MkDocs YAML front matter:

---
graphviz:
  common:
    graph:
      rankdir: LR
  dark:
    node:
      color: "#FFFFFF"
---

Per graph

A Graphviz fence may start with its own YAML header:

```dot
---
common:
  graph:
    rankdir: LR
light:
  node:
    color: "#0055AA"
dark:
  node:
    color: "#88CCFF"
---
digraph G {
    A -> B
}
```

The header is consumed by mkdocs-graphviz and is never sent to Graphviz.

External .dot files

Keep a graph in a separate file under docs_dir and render it with:

{{ graphviz("../graphs/example.dot") }}

Relative paths are resolved from the current Markdown page. A path beginning with / is resolved from docs_dir. Imports may not escape docs_dir. Imported .dot files may use the same optional per-graph YAML header.

Generic Graphviz attributes

mkdocs-graphviz does not hard-code one Python option per Graphviz attribute. Entries under graph, node, and edge are translated generically to Graphviz -G, -N, and -E default attributes.

common:
  graph:
    rankdir: LR
    splines: ortho
    nodesep: 0.5
  node:
    shape: box
    style: rounded
    penwidth: 1.5
  edge:
    arrowhead: diamond
    arrowsize: 0.8

The bundled offline schema is used only for diagnostics:

validation: warn   # off | warn | strict

warn is the default. Unknown or wrong-scope attributes produce a build warning but are still passed unchanged to Graphviz. strict turns them into build errors. off performs no schema validation.

Refresh the bundled schema deliberately with:

yarn schema:update

yarn bfc runs the offline yarn schema:check; it intentionally does not perform a network update.

Light/Dark architecture

If the effective Light and Dark configurations are identical, the graph is rendered once. If they differ, Graphviz renders two independent SVGs at build time. The tiny bundled browser runtime only selects the correct already-rendered variant. This permits theme-specific attributes that alter layout, shape, dimensions, fonts, or any other Graphviz behavior; it does not rely on recoloring an SVG after the fact.

The runtime exposes:

window.MkDocsGraphviz.refresh(root)
window.MkDocsGraphviz.setTheme(root, "light")
window.MkDocsGraphviz.setTheme(root, "dark")
window.MkDocsGraphviz.setTheme(root, "auto")

It is designed to tolerate dynamic DOM insertion and hidden/revealed content and includes an optional adapter registration for mkdocs-revealjs without introducing a hard dependency on RevealJS.

Development workflow

yarn dev
yarn dev:lan
yarn build
yarn build:python
yarn build:docs
yarn build:full
yarn build:full:check
yarn bfc
yarn zip

package.json is the single source of truth for the project version. yarn version:sync generates src/mkdocs_graphviz/_version.py.

yarn dev keeps the project installed in Python editable mode, so other MkDocs projects can use the current local source without reinstalling after each change.

Compatibility target

The HTML/runtime architecture is designed for ordinary MkDocs pages and nested/dynamic content such as admonitions, Content Tabs, mkdocs-maths-admonitions, mkdocs-xtables, mkdocs-superquiz, and mkdocs-revealjs. Integration tests cover the generic nesting behavior; project-specific compatibility can be extended without coupling the Graphviz renderer to those plugins.

License

GNU GPL v3 or later. See LICENSE.

Metadata

Release files for mkdocs-graphviz 2.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mkdocs-graphviz 2.0.2
File Size Uploaded
mkdocs_graphviz-2.0.2.tar.gz 36.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mkdocs-graphviz 2.0.2
File Interpreter ABI Platform
mkdocs_graphviz-2.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 69.7 kB

Release files / mkdocs_graphviz-2.0.2.tar.gz

Download URL mkdocs_graphviz-2.0.2.tar.gz
Size 36.6 kB
Tags Source
SHA-256 checksum
How to use checksums
38dc26c4f439b5ebbb8c99f6b173285b0aee923957c9ea6e5bced82f99d1cb23
BLAKE2b-256 checksum
How to use checksums
51a7e8ba623a3ee452b225e1b3aac72b3f66d50c3a78215d90256f81eb42b2dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / mkdocs_graphviz-2.0.2-py3-none-any.whl

Download URL mkdocs_graphviz-2.0.2-py3-none-any.whl
Size 33.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f056eca2ffb975cfcb495711b60fb5fd2e4926707028f6cdac44afca709c35e2
BLAKE2b-256 checksum
How to use checksums
3fa1244603555f2b4bff0b4a2919ecd44bedd55fdbfa022356d17eb20debfcc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

2.0.2 This release

2 release files

2.0.1

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5

2 release files

1.4.87

2 release files

1.4.85

2 release files

1.4.9

2 release files

1.4.8

2 release files

1.4.7

2 release files

1.4.6

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3

2 release files

1.2.1

2 release files

1.2

2 release files

1.1

2 release files

1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page