Introduction

This module provides methods to generate SVGs using D2 diagram syntax.

The primary use case for this module is:

  • Generating diagrams using D2 syntax

A submodule also provides a text filter that allows embedding D2 diagrams in content.

Usage

The easiest way to get started with D2 is to enable the d2_filter submodule and configure a text format to use it.

For more advanced use-cases, you can generate SVGs from D2 like so:

use Drupal\d2\D2Helper;

# Generate an SVG or use a cached copy if available (highly recommended).
$svg = (new D2Helper())->getSvg($d2_input, $d2_options);

If you want an uncached SVG, call the underlying library:

use Consensus\PhpD2\D2;

# Generate an SVG.
$svg = (new D2())->generateSvg($d2_input, $d2_options);

Similar projects

MermaidJS is a mature Javascript library that generates diagrams and charts in-browser. Drupal support is provided by the Mermaid Integration module.

Supporting this module

Contact the module maintainers if you'd like to support development, or request a specific feature.

Community documentation

For more information, check out the D2 website and documentation.

Maintainers

Current maintainers for Drupal 11:

Supporting organizations: 
Module development and maintenance

Project information

Releases