terrastruct/d2
Fork: 421 Star: 16763 (更新于 2024-10-31 15:05:59)
license: MPL-2.0
Language: Go .
D2 is a modern diagram scripting language that turns text to diagrams.
最后发布版本: v0.6.7 ( 2024-09-29 07:27:22)
A modern diagram scripting language that turns text to diagrams.
Docs | Cheat sheet | Comparisons | Playground
https://user-images.githubusercontent.com/3120367/206125010-bd1fea8e-248a-43e7-8f85-0bbfca0c6e2a.mp4
Table of Contents
- What does D2 look like?
- Quickstart
- Install
- D2 as a library
- Themes
- Fonts
- Export file types
- Language tooling
- Plugins
- Comparison
- Contributing
- License
- Related
- FAQ
- Notable open-source projects documenting with D2
What does D2 look like?
vars: {
d2-config: {
layout-engine: elk
# Terminal theme code
theme-id: 300
}
}
network: {
cell tower: {
satellites: {
shape: stored_data
style.multiple: true
}
transmitter
satellites -> transmitter: send
satellites -> transmitter: send
satellites -> transmitter: send
}
online portal: {
ui: {shape: hexagon}
}
data processor: {
storage: {
shape: cylinder
style.multiple: true
}
}
cell tower.transmitter -> data processor.storage: phone logs
}
user: {
shape: person
width: 130
}
user -> network.cell tower: make call
user -> network.online portal.ui: access {
style.stroke-dash: 3
}
api server -> network.online portal.ui: display
api server -> logs: persist
logs: {shape: page; style.multiple: true}
network.data processor -> api server
Open in playground
For more examples, see ./docs/examples.
Quickstart
The most convenient way to use D2 is to just run it as a CLI executable to
produce SVGs from .d2
files.
# First, install D2
curl -fsSL https://d2lang.com/install.sh | sh -s --
echo 'x -> y -> z' > in.d2
d2 --watch in.d2 out.svg
A browser window will open with out.svg
and live-reload on changes to in.d2
.
Install
The easiest way to install is with our install script:
curl -fsSL https://d2lang.com/install.sh | sh -s --
You can run the install script with --dry-run
to see the commands that will be used
to install without executing them.
Or if you have Go installed you can install from source though you won't get the manpage:
go install oss.terrastruct.com/d2@latest
You can also install a release from source which will include manpages. See ./docs/INSTALL.md#source-release.
To uninstall with the install script:
curl -fsSL https://d2lang.com/install.sh | sh -s -- --uninstall
For detailed installation docs, see ./docs/INSTALL.md. We demonstrate alternative methods and examples for each OS.
As well, the functioning of the install script is described in detail to alleviate any concern of its use. We recommend using your OS's package manager directly instead for improved security but the install script is by no means insecure.
D2 as a library
In addition to being a runnable CLI tool, D2 can also be used to produce diagrams from Go programs.
For examples, see ./docs/examples/lib. This blog post also demos a complete, runnable example of using D2 as a library for a real-world use case.
Themes
D2 includes a variety of official themes to style your diagrams beautifully right out of the box. See ./d2themes to browse the available themes and make or contribute your own creation.
Fonts
D2 ships with "Source Sans Pro" as the font in renders. If you wish to use a different one, please see ./d2renderers/d2fonts.
Export file types
D2 currently supports SVG, PNG and PDF exports. More coming soon.
Language tooling
D2 is designed with language tooling in mind. D2's parser can parse multiple errors from a broken program, has an autoformatter, syntax highlighting, and we have plans for LSP's and more. Good language tooling is necessary for creating and maintaining large diagrams.
The extensions for VSCode and Vim can be found in the Related section.
Plugins
D2 is designed to be extensible and composable. The plugin system allows you to change out layout engines and customize the rendering pipeline. Plugins can either be bundled with the build or separately installed as a standalone binary.
Layout engines:
- dagre (default, bundled): A fast, directed graph layout engine that produces layered/hierarchical layouts. Based on Graphviz's DOT algorithm.
- ELK (bundled): A directed graph layout engine particularly suited for node-link diagrams with an inherent direction and ports.
- TALA (binary): Novel layout engine designed specifically for software architecture diagrams. Requires separate install, visit the Github page for more.
D2 intends to integrate with a variety of layout engines, e.g. dot
, as well as
single-purpose layout types like sequence diagrams. You can choose whichever layout engine
you like and works best for the diagram you're making.
Comparison
For a comparison against other popular text-to-diagram tools, see https://text-to-diagram.com.
Contributing
Contributions are welcome! See ./docs/CONTRIBUTING.md.
License
Open sourced under the Mozilla Public License 2.0. See ./LICENSE.txt.
Related
We are constantly working on new plugins, integrations, extensions. Contributions are welcome in any official or community plugins. If you have somewhere in your workflow that you want to use D2, feel free to open a discussion. We have limited bandwidth and usually choose the most high-demand ones to work on. If you make something cool with D2 yourself, let us know and we'll be happy to include it here!
Official plugins
- VSCode extension: https://github.com/terrastruct/d2-vscode
- Vim extension: https://github.com/terrastruct/d2-vim
- Obsidian plugin: https://github.com/terrastruct/d2-obsidian
- Slack app: https://d2lang.com/tour/slack
- Discord plugin: https://d2lang.com/tour/discord
Community plugins
- Tree-sitter grammar: https://git.pleshevski.ru/pleshevskiy/tree-sitter-d2
- Emacs major mode: https://github.com/andorsk/d2-mode
- Goldmark extension: https://github.com/FurqanSoftware/goldmark-d2
- Telegram bot: https://github.com/meinside/telegram-d2-bot
- Postgres importer: https://github.com/zekenie/d2-erd-from-postgres
- Structurizr to D2 exporter: https://github.com/goto1134/structurizr-d2-exporter
- MdBook preprocessor: https://github.com/danieleades/mdbook-d2
- ROS2 D2 Exporter: https://github.com/Greenroom-Robotics/ros-d2
- D2 org-mode support: https://github.com/xcapaldi/ob-d2
- Python D2 diagram builder: https://github.com/MrBlenny/py-d2
- Clojure D2 transpiler: https://github.com/judepayne/dictim
- JavaScript D2 diagram builder: https://github.com/Kreshnik/d2lang-js
- C# & dotnet SDK: https://github.com/Stephanvs/d2lang-cs
- Maven plugin: https://github.com/andrinmeier/unofficial-d2lang-maven-plugin
- Confluence plugin: https://github.com/andrinmeier/unofficial-d2lang-confluence-plugin
- CIL (C#, Visual Basic, F#, C++ CLR) to D2: https://github.com/HugoVG/AppDiagram
- D2 Snippets (for text editors): https://github.com/Paracelsus-Rose/D2-Language-Code-Snippets
- Mongo to D2: https://github.com/novuhq/mongo-to-D2
- Pandoc filter: https://github.com/ram02z/d2-filter
- Logseq-D2: https://github.com/b-yp/logseq-d2
- ent2d2: https://github.com/tmc/ent2d2
- MkDocs Plugin: https://github.com/landmaj/mkdocs-d2-plugin
- Remark Plugin: https://github.com/mech-a/remark-d2
- Zed extension: https://github.com/gabeidx/zed-d2
Misc
- Comparison site: https://github.com/terrastruct/text-to-diagram-site
- Playground: https://github.com/terrastruct/d2-playground
- Language docs: https://github.com/terrastruct/d2-docs
- Hosted icons: https://icons.terrastruct.com
FAQ
- Does D2 collect telemetry?
- No, D2 does not use an internet connection after installation, except to check for version updates from Github periodically.
- Does D2 need a browser to run?
- No, D2 can run entirely server-side.
- What's coming in the next release?
- I have a question or need help.
- The best way to get help is to ask on D2 Discord
- I have a feature request, proposal, or bug report.
- Please open up a Github Issue.
- I have a private inquiry.
- Please reach out at hi@d2lang.com.
Notable open-source projects documenting with D2
Do you have or see an open-source project with .d2
files? Please submit a PR adding to
this selected list of featured projects using D2.
- ElasticSearch
- Sourcegraph
- Temporal
-
Tauri
- Rust GUI framework (78.5k stars)
- Intellij
- Coder
- UC Berkeley
-
Coronacheck
- Official app of the Netherlands for coronavirus entry passes.
-
Block
Protocol
- The Block Protocol is an open standard for building and using data-driven blocks (1.2k stars).
-
Dagger
- A programmable CI/CD engine that runs your pipelines in containers (8k stars).
-
Ivy
Wallet
- Open-source money manager app for Android (1.1k stars).
-
LocalStack
- Cloud service emulator (46k stars)
-
Queue Library
- Queue is a Golang library for spawning and managing a Goroutine pool
最近版本更新:(数据更新于 2024-10-08 14:47:40)
2024-09-29 07:27:22 v0.6.7
2024-08-02 12:02:22 v0.6.6
2024-04-18 13:18:40 v0.6.5
2024-04-11 14:03:25 v0.6.4
2023-12-17 07:27:58 v0.6.3
2023-12-07 08:19:59 v0.6.2
2023-09-27 02:45:33 v0.6.1
2023-07-31 13:41:48 v0.6.0
2023-06-10 11:35:04 v0.5.1
2023-06-09 12:28:35 v0.5.0
主题(topics):
developer-tools, diagramming, diagrams, go, golang, software-architecture, text-to-diagram
terrastruct/d2同语言 Go最近更新仓库
2024-11-21 22:49:20 containerd/containerd
2024-11-21 13:50:50 XTLS/Xray-core
2024-11-21 07:36:18 kubernetes/kubernetes
2024-11-21 06:27:30 ollama/ollama
2024-11-21 05:17:55 Melkeydev/go-blueprint
2024-11-21 04:04:03 dolthub/dolt