Skip to main content

Graphviz: A Plugin for Pelican

Build Status PyPI Version License

Graphviz is a Pelican plugin that allows the inclusion of Graphviz images using the Markdown markup format. The code for the Graphviz figure is included as a block in the article’s source, and the image is embedded in HTML using the Base64 format.

Installation

This plugin can be installed via:

python -m pip install pelican-graphviz

Graphviz must be installed on the system, otherwise this plugin will be deactivated. Graphviz can be installed on Debian-based systems via:

sudo aptitude install graphviz

For macOS, Graphviz can be installed via Homebrew:

brew install graphviz

Usage

In the Markdown source, the Graphviz code must be inserted as an individual block (i.e., separated from the rest of the material by blank lines), like the following:

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

This will insert an image in your article like this:

figure

The block must start with ..graphviz (this is configurable — see below). The word dot in the first line indicates the program that will be run 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 in the second line of the block. Notice that newlines are not allowed inside the Graphviz block.

Styling with CSS

The image is generated in HTML with an <img> element inside an HTML element (by default a <div>, but this is configurable — see below). The latter has class graphviz (this is also configurable — see below). A 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 set in the Pelican settings file:

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

  • GRAPHVIZ_IMAGE_CLASS: Class of the <div> element including the generated Graphviz image (defaults to 'graphviz').

  • GRAPHVIZ_BLOCK_START: Starting tag for the Graphviz block in Markdown (defaults to '..graphviz').

Output Image Format

The format of the embedded image is SVG, and there is currently no way to change it. This format was chosen over others (like PNG) for two reasons. First, the generated SRC string in Base64 seem to be shorter for SVG than for PNG. Second, the image will be available in the browser in a high-quality vectorized format. As a caveat, notice that this choice may prevent display in browsers lacking proper SVG support.

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 this Graphviz plugin uses the Markdown extension syntax ..graphviz <program> […]. Regarding the rendered output, the differences are:

  • Both plugins output an element with 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,[…]", while 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 this 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 this Graphviz plugin produces a vector image that can be zoomed without image quality loss.
  • Liquid Tags outputs the Graphviz image inside a <span>, whereas this Graphviz plugin offers a choice for the container element.

To-Do

Contributions that make this plugin work with reStructuredText content would be welcome.

Contributing

Contributions are welcome and much 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.

License

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

This project is licensed under the AGPL 3.0 license.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pelican-graphviz-1.0.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pelican_graphviz-1.0.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file pelican-graphviz-1.0.0.tar.gz.

File metadata

  • Download URL: pelican-graphviz-1.0.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.2 Linux/5.4.0-1043-azure

File hashes

Hashes for pelican-graphviz-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6704d0bb63ddbb0ce37c89e6ca9c81567e7afed39a239ce20e5e97dacd9d55c2
MD5 c95fd117e059c3e6491d2a1daca56876
BLAKE2b-256 91e66a4fc16a1ebaa604a76adda8574510cbc21d323eb0cd12b7ff1a3364415b

See more details on using hashes here.

File details

Details for the file pelican_graphviz-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pelican_graphviz-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.2 Linux/5.4.0-1043-azure

File hashes

Hashes for pelican_graphviz-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed6e6fd53df04a6cd4463dbce6a4a0fffdf25ab9629651aa593c8545e84f8d3f
MD5 5c802e602f040b3e053b95dbf00bdc63
BLAKE2b-256 436e2b96e0a9770a84137c2d5efca8ecfed8f49299a9e9eb9d4ec62e79e40977

See more details on using hashes here.

Release history Release notifications | RSS feed

2.0.1

2 files

2.0.0

2 files

1.3.1

2 files

1.3.0

2 files

1.2.5

2 files

1.2.4

2 files

1.2.3

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.0

2 files

1.0.1

2 files

This release

1.0.0 This release

2 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