Drupal is a registered trademark of Dries Buytaert

d2

Security covered
View on drupal.org

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:

Activity

Total releases
8
First release
Jan 2026
Latest release
3 weeks ago
Release cadence
5 days
Stability
0% stable

Release Timeline

Releases

Version Type Release date
1.0.0-beta0 Pre-release Feb 4, 2026
1.0.0-alpha5 Pre-release Jan 13, 2026
1.0.0-alpha4 Pre-release Jan 12, 2026
1.0.0-alpha3 Pre-release Jan 9, 2026
1.0.0-alpha2 Pre-release Jan 8, 2026
1.0.0-alpha1 Pre-release Jan 6, 2026
1.0.0-alpha0 Pre-release Jan 5, 2026
1.0.x-dev Dev Jan 1, 2026