Skip to content
/ ob-d2 Public

Org-Babel support for evaluating d2 diagram scripting language

License

Notifications You must be signed in to change notification settings

xcapaldi/ob-d2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MELPA

Introduction

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
hello world

Language Specific Header Arguments

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.

Additional Examples

All examples are courtesy of Terrastruct, Inc. who published them in their D2 documentation.

Flags to specify theme and sketch format

#+BEGIN_SRC d2 :file flags.png :flags -t 101 -s
High Mem Instance -> EC2 <- High CPU Instance: Hosted By
#+END_SRC
flags

Complex example

#+BEGIN_SRC d2 :file complex.png
clouds: {
  aws: {
    load_balancer -> api
    api -> db
  }
  gcloud: {
    auth -> db
  }

  gcloud -> aws
}
#+END_SRC
complex

Configuration

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))))

Manual installation

Download ob-d2.el from this repository to your loadpath and include (require 'ob-d2) in your init.el file.

About

Org-Babel support for evaluating d2 diagram scripting language

Resources

License

Stars

Watchers

Forks

Packages

No packages published