ob-d2
enables Org-Babel support for evaluating D2 code.
It was created based on the usage of ob-ditaa.
The D2 code is compiled via the d2
command.
#+BEGIN_SRC d2 :file hello.png
x -> y: hello world
#+END_SRC
In addition to the normal header arguments for Babel, ob-d2
uses the :flags
header to pass additional flags to the d2
command.
:file
is required since the output of D2 is an image.
All examples are courtesy of Terrastruct, Inc. who published them in their D2 documentation.
#+BEGIN_SRC d2 :file flags.png :flags -t 101 -s
High Mem Instance -> EC2 <- High CPU Instance: Hosted By
#+END_SRC
#+BEGIN_SRC d2 :file complex.png
clouds: {
aws: {
load_balancer -> api
api -> db
}
gcloud: {
auth -> db
}
gcloud -> aws
}
#+END_SRC
ob-d2
is available from Melpa.
You can install it directly via package-install
if you have Melpa in your package archives.
After installation, you can (require 'ob-d2)
and enable D2 as a supported language in org-mode by adding it to org-babel-load-languages
.
For example, something like:
(org-babel-do-load-languages
'org-babel-load-languages
'((shell . t)
(python . t)
(d2 . t)))
If you use use-package, you can install ob-d2
and ensure org
is configured to use it after loading:
(use-package ob-d2
:ensure t)
(use-package org
:after ob-d2
:config
(org-babel-do-load-languages
'org-babel-load-languages
'((d2 . t))))
Download ob-d2.el
from this repository to your loadpath and include (require 'ob-d2)
in your init.el
file.