Markdown Inline Graphviz Extension

1.1.3 · active · verified Thu Apr 16

The `markdown-inline-graphviz-extension` library is a Python Markdown extension that allows rendering of Graphviz DOT language diagrams directly within Markdown documents, replacing inline definitions with inline SVG or PNG images. It is a Python 3 fork and continuation of previous projects, designed to work seamlessly with any Python-Markdown-based static site generator. Its current version is 1.1.3, with updates occurring on an as-needed basis to ensure compatibility and address issues.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse Markdown text containing inline Graphviz definitions using the `markdown_inline_graphviz` extension and print the resulting HTML. It is crucial to have the Graphviz 'dot' executable (and other layout engines like 'neato') installed on your system and available in your system's PATH for this extension to function correctly. The example includes both `dot` and `neato` graph definitions.

import markdown
import os

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

markdown_text = """
# My Document with a Graph

Here is a simple graph:

{% dot example.svg
digraph G {
    A -> B;
    B -> C;
    C -> A;
}
%}

Another graph using a different engine:

{% neato another.svg
node [shape=box];
A -- B;
B -- C;
C -- A;
%}

"""

# Render the markdown with the inline_graphviz extension
# Ensure the extension name is exactly 'markdown_inline_graphviz'
try:
    html_output = markdown.markdown(markdown_text, extensions=['markdown_inline_graphviz'])
    print(html_output)
except Exception as e:
    print(f"Error rendering markdown: {e}")
    print("Please ensure Graphviz is installed on your system and its executables are in your PATH.")
    print("You can test by running 'dot -V' or 'neato -V' in your terminal.")

view raw JSON →