Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

This module allows you to generate SVG diagrams from D2 syntax. It includes a text filter to embed these diagrams directly into your Drupal content. You can also generate SVGs programmatically for more advanced use cases.

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
5 months ago
Releases (12 mo)
8 ▲ from 0
Maintenance
Active

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