Getting Started
An Astro integration and remark plugin to transform D2 Markdown code blocks into diagrams.
Check out the examples for previews of some diagrams you can create with D2.
Prerequisites
- You will need to have an Astro set up. If you don’t have one yet, you can follow the installation guide in the Astro docs to create one.
- You will also need to have D2 installed. You can follow the installation instructions to install D2 on various platforms.
Installation
Astro D2 is an Astro integration.
Astro includes an astro add command to automate the setup of integrations.
If you prefer, you can install the integration manually instead.
To install astro-d2, run the following from your project directory and follow the prompts:
npx astro add astro-d2pnpm astro add astro-d2yarn astro add astro-d2bun run --bun astro add astro-d2nr astro add astro-d2Manual Install
First, install the astro-d2 integration using your favorite package manager:
npm install astro-d2pnpm add astro-d2yarn add astro-d2bun add astro-d2ni astro-d2Then, add the integration to your astro.config.mjs file using the integrations property:
import { defineConfig } from 'astro/config'import astroD2 from 'astro-d2'
export default defineConfig({ // … integrations: [astroD2()],})Editor Integration
For editor support in Visual Studio Code, install the official D2 extension.
For other editors, you can check the list of official and community-developed plugins and extensions.
Usage
With the Astro D2 integration, you can create a D2 diagram by using a Markdown code block which is indicated by a block with three backticks ``` at the start and end and by specifying the D2 language after the opening backticks.
```d2direction: rightinstallation -> configuration```The above code block will be rendered as the following diagram:
The Astro D2 instegration behavior can be tweaked using various configuration options and individual diagrams can be customized using attributes.
Note that when deploying your site, you will need to ensure that D2 is installed as well or use the skipGeneration configuration option.
Lean more about deploying your site using the Astro D2 integration.