Generate d2 diagrams using org-mode and org-babel.
- install d2
- Until the package is in melpa, you can use straight or similar:
(use-package ob-d2
:straight (:type git :host github :repo "dmacvicar/ob-d2")
:defer t)
- Add
d2
toorg-babel-load-languages
or specify:commands (org-babel-execute:d2)
when loading it.(org-babel-do-load-languages 'org-babel-load-languages '((d2 . t) (scheme . t) (your-other-langs . t)))
- Open
org-mode
buffer and create anorg-babel
source block:#+begin_src d2 :file test.png A-->B: Works! #+end_src
A-->B: Works!
- Exporting the
org-mode
document or invoking theorg-babel-execute-src-block
function to generate diagram.
file
- Output file. It should be either svg or png.
theme
- Theme of the chart (number). See available themes.
layout
- Layout engine (default is “dagre”)