Create declarative diagrams in Inkscape using D2's modern diagramming language
Transform simple text descriptions into beautiful, professional diagrams directly within Inkscape. D2 offers a cleaner syntax than traditional tools, with automatic layout algorithms and stunning visual output.
- Demo
- Features
- Why D2?
- Requirements
- Installation
- Quick Start
- Usage Guide
- Configuration
- Examples
- Troubleshooting
- Contributing
- License
-
π Full D2 Support
- All diagram types and features
- Native SVG output for full editability
- High-quality PNG export option
-
π¨ Professional Styling
Feature Description 8 Themes From neutral to colorful options Sketch Mode Hand-drawn aesthetic 4 Layout Engines Dagre, ELK, TALA, Custom Custom Fonts Regular, italic, and bold -
π Smart Positioning
- 9 preset positions (center, corners, edges)
- Selection-relative placement
- Custom X/Y offsets
- Page or viewport alignment
-
π§ Advanced Features
- Direct SVG import (fully editable)
- Auto-scaling to fit dimensions
- Layer management
- Object locking
- Metadata support (title, description)
D2 is a modern diagram scripting language designed for clarity and aesthetics:
| Feature | D2 | Traditional Tools |
|---|---|---|
| Syntax | Clean, readable | Often verbose |
| Auto-layout | Built-in, smart | Manual positioning |
| Styling | Simple inline | Separate config |
| Connections | Intuitive arrows | Complex syntax |
| Containers | Easy nesting | Difficult grouping |
| Icons | Built-in library | External dependencies |
D2 Example:
server -> database: queries
database -> server: resultsThis simple text produces a professional diagram with automatic layout!
| Component | Version | Purpose |
|---|---|---|
| Inkscape | 1.0+ | Vector graphics editor |
| D2 | 0.6+ | Diagram generation CLI |
| Component | Purpose |
|---|---|
| Pillow (Python) | Automatic PNG dimension detection |
| TALA | Advanced layout engine (commercial) |
Windows
Option A: Using winget (Recommended)
winget install terrastruct.d2Option B: Using Chocolatey
choco install d2Option C: Manual Installation
- Download from D2 Releases
- Extract to a folder (e.g.,
C:\Program Files\D2) - Add to system PATH
Verify installation:
d2 --versionmacOS
# Using Homebrew (Recommended)
brew install d2
# Or using curl
curl -fsSL https://d2lang.com/install.sh | sh -s --Verify installation:
d2 --versionLinux
# Universal installer (Recommended)
curl -fsSL https://d2lang.com/install.sh | sh -s --
# Ubuntu/Debian (via .deb)
# Download .deb from releases page
sudo dpkg -i d2_x.x.x_amd64.deb
# Arch Linux (AUR)
yay -S d2Verify installation:
d2 --version
# Should output: v0.x.xLocate your Inkscape extensions directory:
| OS | Path |
|---|---|
| Windows | C:\Users\[YourName]\AppData\Roaming\inkscape\extensions\ |
| macOS | ~/Library/Application Support/org.inkscape.Inkscape/config/inkscape/extensions/ |
| Linux | ~/.config/inkscape/extensions/ |
π‘ Tip: In Inkscape: Edit β Preferences β System shows extensions path
Install files:
-
Create extension folder:
mkdir -p [extensions-directory]/d2_ink
-
Copy files:
cp d2_diagram.py [extensions-directory]/d2_ink/ cp d2_diagram.inx [extensions-directory]/d2_ink/
-
Set permissions (Linux/macOS):
chmod +x [extensions-directory]/d2_ink/d2_diagram.py
-
Restart Inkscape
- Open Inkscape
- Navigate to Extensions β Render β D2 Diagram
- Extension dialog should appear
- Open Inkscape
- Go to Extensions β Render β D2 Diagram
- In the Diagram tab, enter:
direction: right
User -> Frontend: request
Frontend -> API: call
API -> Database: query
Database -> API: data
API -> Frontend: response
Frontend -> User: display- Click Apply
Your diagram appears in the document, fully editable as SVG!
| Tab | Purpose |
|---|---|
| Diagram | Enter D2 code or load from file |
| Style | Theme, layout engine, sketch mode |
| Format | Output format, scale, quality |
| Position | Placement and alignment options |
| Scale | Auto-scaling and size limits |
| Config | CLI path, custom fonts |
| Advanced | Timeout, temp files, quiet mode |
| Layer | Layer management, object properties |
Enter D2 syntax directly in the code field:
x -> y: connection
y -> z- Check "Use external file"
- Enter path to
.d2file - Click Apply
# Basic arrow
a -> b
# Labeled connection
a -> b: sends data
# Bidirectional
a <-> b: communicates# Different shapes
server: Server {shape: cylinder}
user: User {shape: person}
cloud: Cloud {shape: cloud}
user -> server -> cloudaws: AWS Cloud {
vpc: VPC {
ec2: EC2 Instance
rds: RDS Database
ec2 -> rds
}
}
user -> aws.vpc.ec2important: Critical System {
style: {
fill: "#ff6b6b"
stroke: "#c92a2a"
font-color: white
bold: true
}
}| Format | Best For | Editable |
|---|---|---|
| SVG | Editing, scalability | β Yes |
| PNG | Presentations, sharing | β No |
| Theme ID | Name | Description |
|---|---|---|
0 |
Default | Neutral, professional |
1 |
Neutral Grey | Subtle grey tones |
3 |
Flagship Terrastruct | Vibrant colors |
4 |
Cool Classics | Blue-based palette |
5 |
Mixed Berry Blue | Purple-blue tones |
6 |
Grape Soda | Purple theme |
7 |
Aubergine | Dark purple |
8 |
Colorblind Clear | Accessibility-focused |
100 |
Terminal | Dark terminal style |
101 |
Terminal Grayscale | Monochrome terminal |
102 |
Origami | Paper-like aesthetic |
| Engine | Description | Best For |
|---|---|---|
dagre |
Default, hierarchical | Most diagrams |
elk |
Eclipse Layout Kernel | Complex graphs |
tala |
Advanced (premium) | Professional layouts |
βββββββββββββββββββββββββββββββββββββββ
β top_left top_center top_right β
β β
β middle_left center middle_right β
β β
β bottom_left bottom_center bottom_right β
βββββββββββββββββββββββββββββββββββββββ
Special options:
- cursor: Place at view center
- Use selection bbox: Position relative to selected object
| Option | Description | Default |
|---|---|---|
| Theme | Color scheme (0-102) | 0 (Default) |
| Layout | Layout engine | dagre |
| Sketch Mode | Hand-drawn style | β |
| Padding | Diagram padding (px) | 100 |
| Option | Description | Default |
|---|---|---|
| Output Format | SVG or PNG | SVG |
| Scale Factor | Size multiplier | 1.0 |
| Quality | PNG resolution (1-4x) | 2 |
| Embed Image | Embed or link PNG | β |
| Option | Description | Default |
|---|---|---|
| Auto Scale | Fit to max dimensions | β |
| Max Width | Maximum width (0=none) | 0 |
| Max Height | Maximum height (0=none) | 0 |
| Maintain Aspect Ratio | Keep proportions | β |
| Lock Object | Prevent edits | β |
| Option | Description | Default |
|---|---|---|
| D2 Path | Path to d2 executable | d2 |
| Font Regular | Custom regular font | (system) |
| Font Italic | Custom italic font | (system) |
| Font Bold | Custom bold font | (system) |
| Inkscape Path | Path to Inkscape CLI | inkscape |
| Option | Description | Default |
|---|---|---|
| Timeout | Generation timeout (sec) | 30 |
| Keep Temp Files | Don't delete temp files | β |
| Temp Directory | Custom temp location | (system) |
| Quiet Mode | Suppress debug output | β |
| Fit to Content | Crop empty space | β |
| Option | Description | Default |
|---|---|---|
| Create Layer | New layer for diagram | β |
| Layer Name | Name for new layer | D2 Diagrams |
| Object ID | Custom SVG ID | (auto) |
| Add Title | Include title element | β |
| Add Description | Include desc element | β |
direction: right
internet: Internet {shape: cloud}
firewall: Firewall {
shape: hexagon
style.fill: "#ffcccc"
}
dmz: DMZ {
web: Web Server {shape: cylinder}
api: API Gateway
}
internal: Internal Network {
app: App Servers {
shape: rectangle
style.multiple: true
}
db: Database {shape: cylinder}
cache: Redis Cache {shape: cylinder}
}
internet -> firewall -> dmz.web
dmz.web -> dmz.api
dmz.api -> internal.app
internal.app -> internal.db
internal.app -> internal.cacheUser -> Login Page: visits
Login Page -> Auth Service: credentials
Auth Service -> Database: validate
Database -> Auth Service: user data
Auth Service -> Token Service: generate JWT
Token Service -> Auth Service: token
Auth Service -> Login Page: success + token
Login Page -> User: redirect to dashboardAnimal: Animal {
shape: class
+name: string
+age: int
+makeSound(): void
}
Dog: Dog {
shape: class
+breed: string
+bark(): void
+fetch(): void
}
Cat: Cat {
shape: class
+indoor: bool
+meow(): void
+purr(): void
}
Animal <- Dog: extends
Animal <- Cat: extendsdirection: right
alice: Alice {shape: person}
bob: Bob {shape: person}
server: Server {shape: cylinder}
alice -> bob: "Hello!"
bob -> alice: "Hi there!"
alice -> server: login request
server -> alice: session token
alice -> bob: "I'm logged in"frontend: Frontend {
icon: https://icons.terrastruct.com/essentials/092-map.svg
react: React App
nginx: Nginx
}
backend: Backend {
icon: https://icons.terrastruct.com/essentials/213-server.svg
api: REST API
worker: Background Worker
}
data: Data Layer {
icon: https://icons.terrastruct.com/essentials/119-database.svg
postgres: PostgreSQL
redis: Redis
s3: S3 Storage {shape: cloud}
}
frontend.react -> backend.api
backend.api -> data.postgres
backend.worker -> data.redis
backend.api -> data.s3Enable Sketch Mode in Style tab for hand-drawn aesthetic:
start: Start {shape: oval}
process: Process Data
decision: Valid? {shape: diamond}
success: Success {
style.fill: "#90EE90"
}
error: Error {
style.fill: "#FFB6C1"
}
end: End {shape: oval}
start -> process
process -> decision
decision -> success: yes
decision -> error: no
success -> end
error -> process: retryusers: users {
shape: sql_table
id: int {constraint: primary_key}
email: varchar(255) {constraint: unique}
name: varchar(100)
created_at: timestamp
}
posts: posts {
shape: sql_table
id: int {constraint: primary_key}
user_id: int {constraint: foreign_key}
title: varchar(200)
content: text
published: boolean
}
comments: comments {
shape: sql_table
id: int {constraint: primary_key}
post_id: int {constraint: foreign_key}
user_id: int {constraint: foreign_key}
body: text
}
users.id <-> posts.user_id
posts.id <-> comments.post_id
users.id <-> comments.user_iddirection: down
ceo: CEO {
shape: person
style.fill: "#4a90d9"
}
cto: CTO {shape: person}
cfo: CFO {shape: person}
coo: COO {shape: person}
engineering: Engineering {
lead: Tech Lead
dev1: Developer
dev2: Developer
}
finance: Finance {
accountant: Accountant
analyst: Analyst
}
operations: Operations {
manager: Manager
support: Support Team
}
ceo -> cto
ceo -> cfo
ceo -> coo
cto -> engineering
cfo -> finance
coo -> operationsExtension not appearing in menu
Solutions:
- Verify files are correctly placed:
ls [extensions-directory]/d2_ink/ # Should show: d2_diagram.py, d2_diagram.inx - Check file permissions:
chmod +x d2_diagram.py
- Restart Inkscape completely
- Check Inkscape error log: Edit β Preferences β System β Open Error Log
D2 CLI not found
Error: D2 CLI not found at: d2
Solutions:
- Verify D2 is installed:
d2 --version
- Install if missing (see Installation section)
- Windows: Use full path in Config tab:
Or add D2 to system PATH
C:\Program Files\D2\d2.exe - Linux/macOS: Find path:
which d2 # Use this path in Config tab
Diagram syntax error
Error: D2 CLI error: ...
Solutions:
- Test syntax in command line:
echo "a -> b" | d2 - output.svg
- Check for:
- Missing colons in labels
- Unclosed braces for containers
- Invalid shape names
- Incorrect style syntax
- Refer to D2 Documentation
SVG import issues
Error: Error importing SVG...
Solutions:
- Try PNG format instead
- Update Inkscape to latest version
- Check temp file permissions
- Enable Keep Temp Files and inspect generated SVG
Diagram appears but positioning is wrong
Solutions:
- Check Position Mode setting
- Verify Align to Page vs viewport setting
- Adjust X/Y Offset values
- Try Auto Scale with max dimensions
Font issues in diagram
Solutions:
- Specify custom fonts in Config tab:
- Font Regular: Path to
.ttfor.otf - Font Bold: Path to bold variant
- Font Italic: Path to italic variant
- Font Regular: Path to
- Use system fonts that D2 can find
- Check font file permissions
Enable detailed output for troubleshooting:
- Uncheck Quiet Mode in Advanced tab
- Check Keep Temp Files
- Run Inkscape from terminal:
inkscape
- Check console for debug output
With Keep Temp Files enabled:
| File | Purpose |
|---|---|
| diagram.d2 | Input D2 code |
diagram.svg |
Generated SVG |
diagram_converted.png |
Converted PNG (if PNG format) |
d2_ink/
βββ d2_diagram.py # Main extension code
βββ d2_diagram.inx # Inkscape extension definition
βββ README.md # This file
βββ examples/ # Example diagrams (optional)
βββ architecture.d2
βββ flowchart.d2
βββ database.d2
| Shape | Syntax | Description |
|---|---|---|
| Rectangle | shape: rectangle |
Default |
| Square | shape: square |
Equal sides |
| Circle | shape: circle |
Round |
| Oval | shape: oval |
Ellipse |
| Diamond | shape: diamond |
Decision |
| Hexagon | shape: hexagon |
Process |
| Cylinder | shape: cylinder |
Database/storage |
| Cloud | shape: cloud |
Cloud service |
| Person | shape: person |
Human actor |
| Package | shape: package |
Module/component |
| Class | shape: class |
UML class |
| SQL Table | shape: sql_table |
Database table |
| Type | Syntax | Description |
|---|---|---|
| Arrow | -> |
Directed |
| Double Arrow | <-> |
Bidirectional |
| Line | -- |
Undirected |
element: Label {
style: {
fill: "#hexcolor"
stroke: "#hexcolor"
stroke-width: 2
stroke-dash: 3
opacity: 0.8
font-color: "#hexcolor"
font-size: 16
bold: true
italic: true
underline: true
shadow: true
multiple: true
3d: true
animated: true
}
}- D2 Documentation: d2lang.com/tour/intro
- D2 Playground: play.d2lang.com
- D2 GitHub: github.com/terrastruct/d2
- Theme Gallery: d2lang.com/tour/themes
- Icon Library: icons.terrastruct.com
Contributions are welcome!
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit changes (
git commit -m 'Add new feature') - Push to branch (
git push origin feature/new-feature) - Open a Pull Request
Development Setup:
git clone https://github.com/YouvenZ/D2_ink.git
cd D2_ink
# Symlink for testing
ln -s $(pwd) ~/.config/inkscape/extensions/d2_inkThis project is licensed under the MIT License - see LICENSE file for details.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- D2 by Terrastruct - The diagram scripting language
- Inkscape - Open source vector graphics
- D2 community for excellent documentation
- β¨ Initial release
- β Full D2 syntax support
- β SVG and PNG output
- β 11 built-in themes
- β Sketch mode
- β Multiple layout engines
- β Auto-scaling
- β Layer management
- β Custom font support
- β Position and alignment options
