Markdown Graphviz Inline
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
- gotcha The underlying `graphviz` Python package (a dependency) requires the Graphviz `dot` executable to be installed on your system and available in the system's PATH. Without it, the extension will fail to render graphs, potentially with errors from the `graphviz` library.
- gotcha The correct extension string to use with `markdown.markdown()` is `'markdown_inline_graphviz'`. Incorrect spelling or capitalization (e.g., `markdown_graphviz_inline`) will prevent the extension from loading and processing graph blocks.
- gotcha This `markdown-graphviz-inline` library is a fork of the original `markdown-inline-graphviz` (by Cesare Morel) providing Python 3 compatibility and continued maintenance. While core functionality remains similar, users migrating from the older library should be aware of potential subtle behavioral differences.
Install
-
pip install markdown-graphviz-inline
Imports
- markdown_inline_graphviz
import markdown html = markdown.markdown(text, extensions=['markdown_inline_graphviz'])
Quickstart
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)