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
d2toorg-babel-load-languagesor 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-modebuffer and create anorg-babelsource block:#+begin_src d2 :file test.png A-->B: Works! #+end_srcA-->B: Works!
- Exporting the
org-modedocument or invoking theorg-babel-execute-src-blockfunction 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”)