Skip to main content

Graphviz: A Plugin for Pelican

Build Status PyPI Version Downloads License

Graphviz is a Pelican plugin enables Graphviz images to be included using the Markdown or reStructuredText markup format. The Graphviz code for the image is included as a block in the article’s source. In the HTML output file, the Graphviz image can appear as either a <svg> element or embedded in an <img> element using the Base64 format.

Installation

This plugin can be installed via:

python -m pip install pelican-graphviz

The newly installed plugin should be detected and enabled automatically, unless the PLUGINS variable is used in the Pelican settings file. In this case, "graphviz" must be added to the existing PLUGINS list. Further information can be found in the How to Use Plugins documentation.

This plugin will be deactivated if Graphviz is not installed on the system. On Debian-based systems, Graphviz can be installed via:

sudo aptitude install graphviz

For macOS, Graphviz can be installed via Homebrew:

brew install graphviz

Usage

Markdown

In the Markdown source, the Graphviz code should be inserted as a separate block, i.e. with blank lines separating it from the surrounding text. An example is shown below:

..graphviz dot
digraph G {
  graph [rankdir = LR];
  Hello -> World
}

This will insert an image into your article, as shown here:

figure

The block must start with ..graphviz (this is configurable — see below). The word dot in the first line indicates which program will be used to produce the image. The available programs are: dot, neato, twopi, circo, fdp, sfdp, and patchwork (see the Graphviz documentation for details). The Graphviz code must start on the second line of the block. Please note that empty lines are not allowed inside the Graphviz block.

reStructuredText

For RST input, support is implemented as a directive, with syntax like:

.. graphviz:: dot
   :alt-text: My graph

   digraph G {
     graph [rankdir = LR];
     Hello -> World
   }

Styling with CSS

The image is generated in HTML using an <img> element inside an HTML element (by default a <div>, but this can be configured — see below). The latter has the class graphviz (this is also configurable — see below). One possible CSS styling would be:

div.graphviz  {
    margin: 10px;
}
div.graphviz img {
    display: block;
    padding: 5px;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    border-style: solid;
    border-width: 1px;
    border-color: rgb(192, 177, 177);
    -webkit-border-radius: 5px;
}

Configuration

The following variables can be configured in the Pelican settings file:

  • GRAPHVIZ_BLOCK_START: Starting tag for the Graphviz block in Markdown (defaults to '..graphviz'). This setting has no effect for reStructuredText input.

  • GRAPHVIZ_HTML_ELEMENT: The HTML element inside which the generated Graphviz image is inserted (defaults to 'div'; another sensible option would be 'span').

  • GRAPHVIZ_IMAGE_CLASS: The class of the <div> element containing the generated Graphviz image (defaults to 'graphviz').

  • GRAPHVIZ_COMPRESS: Compress the resulting SVG XML to an image (defaults to True). Without compression, more SVG features are available, for instance the inclusion of clickable URLs inside the Graphviz diagram.

  • GRAPHVIZ_ALT_TEXT: The string that will be used as the default value for the alt property of the generated <img> HTML element (defaults to "[GRAPH]"). It is only meaningful when the resulting SVG output is compressed.

The values for all variables above, except GRAPHVIZ_BLOCK_START, can be overridden for each block individually using the following syntax in Markdown:

..graphviz [key1=val1, key2="val2"...] dot

If the value includes a comma (,) or an equal sign (=), then use the key2="val2" form.

Or in reStructuredText:

.. graphviz:: dot
   :key1: val1
   :key2: val2

The allowed keys are html-element, image-class, alt-text, and compress. For the latter, the value can be either yes or no.

Output Image Format

The embedded image is in SVG format, and cannot currently be changed. This format was chosen over others, such as PNG, for two reasons. First, the generated Base64 src string is usually shorter shorter for SVG than for PNG. Second, the image will be available in a high-quality vectorized format when displayed in the browser. However, note that this choice may prevent display in browsers lacking proper SVG support.

Text alternative for the image

When generating compressed SVG images (the default), an <img> element will appear in the HTML output. According to the Web Content Accessibility Guidelines, non-text content, such as <img> elements, should have an text alternative. The graphviz plugin complies with this recommendation and always generate an alt property for the generated <img> element. The value of the alt property will be, in order of priority:

  1. The value of the Graphviz block option alt-text,
  2. the ID of the Graphviz element ("G" in the example above), or
  3. the value of the global configuration variable GRAPHVIZ_ALT_TEXT.

Alternatives

An alternative to this plugin is the Graphviz tag provided by the Liquid Tags plugin, which differs from this plugin in several respects. First, the Liquid Tags version uses the syntax {% graphviz { <program> […] } %}, while the graphviz plugin uses the Markdown extension syntax ..graphviz <program> […]. The differences in the rendered output are:

  • Both plugins output an element with the attribute class="graphviz". However, only the graphviz plugin allows you to change the class name via a configuration variable (GRAPHVIZ_IMAGE_CLASS).
  • Liquid Tags encodes the image as src="data:image/png;base64,[…]", whereas the graphviz plugin encodes it as src="data:image/svg+xml;base64,[…]". This has two impacts. First, the size of the HTML code produced by the graphviz plugin is much smaller. For example, the Base64 string for the graphviz code digraph graphname {a -> b -> c; b -> d;} is four times smaller. Second, the Liquid Tags version generates a raster image file, whereas the graphviz plugin produces a vector image that can be zoomed in on without losing image quality.
  • Liquid Tags outputs the Graphviz image inside a <span>, whereas the graphviz plugin offers a choice for the container element.

Contributing

Contributions are welcome and greatly appreciated. Every little bit helps. You can contribute by improving the documentation, adding missing features, and fixing bugs. You can also help out by reviewing and commenting on existing issues.

To start contributing to this plugin, review the Contributing to Pelican documentation, beginning with the Contributing Code section.

Acknowledgments

Thanks to Justin Mayer, for helping with migration of this plugin under the Pelican Plugins organization, and to Maxim Kochurov, for introducing the GRAPHVIZ_COMPRESS configuration variable.

Thanks to weeheavy for suggesting the addition of the alt property to the HTML <img> generated element (issue #30).

Thanks to Mark Shroyer for fixing lint issues, re-enabling the unit test TestGraphvizAltTextWithoutID (PR #31) and adding reStructuredText supoort (PRs #34 and #35)

Authors

Copyright © 2015, 2021, 2023–2025 Rafael Laboissière rafael@laboissiere.net

Copyright © 2025 Mark Shroyer mark@shroyer.name

License

This project is licensed under the terms of the AGPL license, version 3.0 or later.

Release files for pelican-graphviz 2.0.1

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

Source distribution (sdist)

Source distribution for pelican-graphviz 2.0.1
File Size Uploaded
pelican_graphviz-2.0.1.tar.gz 34.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pelican-graphviz 2.0.1
File Interpreter ABI Platform
pelican_graphviz-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 61.5 kB

Release files / pelican_graphviz-2.0.1.tar.gz

Download URL pelican_graphviz-2.0.1.tar.gz
Size 34.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e7d6010894deaab5b89eafb0892e332d9389d942ec0130512ae5e6d78472f5d9
BLAKE2b-256 checksum
How to use checksums
177d7e62b8bd67a1040a505afff688521021e12ddb01e310c335f9df84f68749
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2025.

Transparency log

Release files / pelican_graphviz-2.0.1-py3-none-any.whl

Download URL pelican_graphviz-2.0.1-py3-none-any.whl
Size 27.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9902da4b5bfca5d97f0ee0d96ba1d9ecdccb43507d5b12fc4d5632b5f99d557a
BLAKE2b-256 checksum
How to use checksums
6634c7942754d82a2b94153e59a8e3ecbc7a5d656313399ad90887e9cf37f94c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

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