A d2 extension for Emacs. This was heavily inspired of Mermaid Mode.
Status: Alpha. Available on Melpa.
It works you can use this to render d2 in both your browser and in an emacs buffer. See Bugs & Issues for known issues.
Table of Contents
d2 binary locationText to graph diagrams are awesome. I used Mermaid.js all the time and it was fantastic, but there were a few things it couldn't do so I wanted to expand my options.
Some things that I've noticed d2 has some interesting support in:
Learn more about d2 here
M-x package-install d2-modeC-c C-c - compile current file to an image
C-c C-f - compile given file to an image
C-c C-b - compile current buffer to an image
C-c C-r - compile current region to an image
C-c C-o - open in the live editor
C-c C-d - open the official doc
Note: All compile commands will open the output in a buffer to view the resulting image.
d2 binary locationYou can specify the location of d2 with the variable d2-location, the default assumes you have the binary in your PATH (and for that you probably want/need to install d2).
You can specify png or svg output format by putting this in your init.el file:
(setq d2-output-format "<OUTPUT_FORMAT")
Options are:
.png.svgDefault is SVG.
By default d2-tmp-dir points to \tmp\. Feel free to set it to a more appropriate location that works for you (e.g. on windows).
To customize the key bindings put this into your init.el ...
(defvar d2-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") 'd2-compile)
(define-key map (kbd "C-c C-f") 'd2-compile-file)
(define-key map (kbd "C-c C-b") 'd2-compile-buffer)
(define-key map (kbd "C-c C-r") 'd2-compile-region)
(define-key map (kbd "C-c C-h") 'd2-compile-file-and-browse)
(define-key map (kbd "C-c C-j") 'd2-compile-buffer-and-browse)
(define-key map (kbd "C-c C-k") 'd2-compile-region-and-browse)
(define-key map (kbd "C-c C-o") 'd2-open-browser)
(define-key map (kbd "C-x C-o") 'd2-view-current-svg)
(define-key map (kbd "C-c C-d") 'd2-open-doc)
map))
See the snippets folder for yas snippets. Start making d2 graphs today!
*browse commands to render it directly in your browser instead!Feel free to open an issue and or contribute to this repo over a PR!
We thank anyone that decides to contribute to this repository and encourage contributions.
Also thank you to @suliveevil for bringing up issues.
589 followers · starred Dec 2022
47 followers · starred Aug 2024
38 followers · starred Dec 2024
A d2 extension for Emacs. This was heavily inspired of Mermaid Mode.
Status: Alpha. Available on Melpa.
It works you can use this to render d2 in both your browser and in an emacs buffer. See Bugs & Issues for known issues.
Table of Contents
d2 binary locationText to graph diagrams are awesome. I used Mermaid.js all the time and it was fantastic, but there were a few things it couldn't do so I wanted to expand my options.
Some things that I've noticed d2 has some interesting support in:
Learn more about d2 here
M-x package-install d2-modeC-c C-c - compile current file to an image
C-c C-f - compile given file to an image
C-c C-b - compile current buffer to an image
C-c C-r - compile current region to an image
C-c C-o - open in the live editor
C-c C-d - open the official doc
Note: All compile commands will open the output in a buffer to view the resulting image.
d2 binary locationYou can specify the location of d2 with the variable d2-location, the default assumes you have the binary in your PATH (and for that you probably want/need to install d2).
You can specify png or svg output format by putting this in your init.el file:
(setq d2-output-format "<OUTPUT_FORMAT")
Options are:
.png.svgDefault is SVG.
By default d2-tmp-dir points to \tmp\. Feel free to set it to a more appropriate location that works for you (e.g. on windows).
To customize the key bindings put this into your init.el ...
(defvar d2-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") 'd2-compile)
(define-key map (kbd "C-c C-f") 'd2-compile-file)
(define-key map (kbd "C-c C-b") 'd2-compile-buffer)
(define-key map (kbd "C-c C-r") 'd2-compile-region)
(define-key map (kbd "C-c C-h") 'd2-compile-file-and-browse)
(define-key map (kbd "C-c C-j") 'd2-compile-buffer-and-browse)
(define-key map (kbd "C-c C-k") 'd2-compile-region-and-browse)
(define-key map (kbd "C-c C-o") 'd2-open-browser)
(define-key map (kbd "C-x C-o") 'd2-view-current-svg)
(define-key map (kbd "C-c C-d") 'd2-open-doc)
map))
See the snippets folder for yas snippets. Start making d2 graphs today!
*browse commands to render it directly in your browser instead!Feel free to open an issue and or contribute to this repo over a PR!
We thank anyone that decides to contribute to this repository and encourage contributions.
Also thank you to @suliveevil for bringing up issues.
589 followers · starred Dec 2022
47 followers · starred Aug 2024
38 followers · starred Dec 2024