D2 is a modern diagram scripting language that turns text into diagrams. The source code for D2, as well as install instructions and all other information, can be found at https://github.com/d2lang/d2.
d2_obsidian_example.mp4
In Obsidian, open Settings → Community plugins → Browse, search for D2, then select Install and Enable.
Write a fenced d2 block in a note to see it rendered in Live Preview or Reading view. The plugin bundles D2.js, including the Dagre, ELK, and TALA layouts. Rendering and formatting work offline on desktop, iPhone, iPad, and Android with just the plugin installed.
To format the D2 source, place the cursor in the block while editing the note and run D2: Format D2 Block from the command palette. The command also works offline on mobile.
Select Save SVG below a diagram to save a copy in the vault’s configured attachment folder. Each save gets its own filename. On Obsidian versions before 1.5.7, the copy is saved beside the note.
Diagrams can import other .d2 files in the vault. For example, ...@shared loads shared.d2 beside the note. Nested imports resolve relative to the importing file. Select Recompile after editing an imported file.
If Obsidian Sync reports that the plugin exceeds your plan’s per-file limit, install or update D2 from Community plugins on each device.
Layout engine: D2 supports multiple layout engines, which can significantly affect the look of your diagram.Theme ID: For a list of available themes, visit the D2 repository.Pad: Number of pixels padded around the rendered diagram.Sketch mode: Render the diagram to look like it was sketched by hand.Container height: Maximum diagram height in pixels.Debounce: Number of milliseconds to wait after a change has made to refresh the diagram (min 100).
Create a fenced codeblock with d2 as the language tag:
Hello -> WorldTo style one diagram, use D2’s native configuration inside its block:
vars: {
d2-config: {
layout-engine: elk
theme-id: 4
pad: 24
sketch: true
}
}
Hello -> WorldNew vaults follow each diagram’s layout, theme, padding, and sketch settings. Existing vaults keep their saved overrides. To follow the diagram for an option, choose Use diagram setting for layout or sketch, or clear the theme ID or padding.
Set vars.d2-config.animate-interval: 1s in a diagram with multiple boards
to animate them in the note. Save SVG preserves the animation in the attachment.
- Clone this repo.
- Run
yarnto install dependencies. - Run
yarn run devto start compilation in watch mode. - Copy over
main.js,styles.css,manifest.jsonto your vault[VaultFolder]/.obsidian/plugins/d2-obsidian/.
Run the offline rendering tests with yarn build, yarn playwright-core install chromium webkit, yarn test:desktop, and yarn test:mobile. The build bundles the browser entry of the official D2.js package, including its worker and compiler. Its version and integrity are pinned in the Yarn lockfile.
- I have a question or need help.
- The best way to get help is to ask on D2 Discord.
- I'd like to contribute.
- We welcome contributions! Please pick one from an existing Issue, or open one if none exists.
- I have a feature request, proposal, or bug report.
- Please open up a Github Issue. If it's D2-specific, please open it in the D2 repository. If it's specific to this plugin, please open it here.
- I have a private inquiry.
- Please reach out at [email protected].