Markdown Graphviz Inline

1.1.3 · active · verified Sat Apr 11

markdown-graphviz-inline is a Python-Markdown extension that enables rendering Graphviz DOT language diagrams directly within Markdown documents. It automatically detects ````graphviz ... ```` code blocks and replaces them with inline SVG images. This library is a Python 3 fork and continuation of the original `markdown-inline-graphviz` by Cesare Morel, currently maintained under the Backstage organization. Its current version is 1.1.3, with updates occurring on an as-needed basis.

Warnings

Install

Imports

Quickstart

Demonstrates how to parse Markdown text containing ````graphviz ... ```` blocks using the `markdown_inline_graphviz` extension and print the resulting HTML. This requires the Graphviz 'dot' executable to be installed on your system.

import markdown

# Ensure Graphviz 'dot' executable is installed on your system and in PATH.
# For example, on Ubuntu: sudo apt-get install graphviz
# On macOS: brew install graphviz

markdown_text = '''
# My Graph Report

Here's a simple directed graph:

```graphviz
digraph G {
    A -> B;
    B -> C;
    C -> A;
}
```

And a more complex one with different shapes:

```graphviz
digraph hierarchy {
    node [shape=box];
    subgraph cluster_0 {
        label = "Parent Process";
        a0 [label="Task 1"];
        a1 [label="Task 2"];
        a2 [label="Task 3"];
    }
    subgraph cluster_1 {
        label = "Child Process";
        b0 [label="Subtask 1"];
        b1 [label="Subtask 2"];
    }
    a0 -> a1 -> a2;
    a2 -> b0;
    b0 -> b1;
}
```
'''

html_output = markdown.markdown(
    markdown_text,
    extensions=['markdown_inline_graphviz']
)

print(html_output)

view raw JSON →