Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

d2

svugy reads d2 v0.9.0 so existing d2 files render without a rewrite.

  • svugy render my.d2 renders the file as it is; svugy import my.d2 -o my.md converts it to Markdown.
  • d2 input gets no features beyond this page: what d2 can’t say, write in Markdown.

The editor holds the Quickstart’s web app written in d2; the SVG re-renders as you type.

What maps

d2svugy
a: { b }b nested in a
a -> b: text, a -> b -> ca labelled edge; one edge per hop
a <- ban edge from b to a
_.xx in the parent scope
linklink
tooltip on a shape or an edgeits description, stored as Markdown
style.fill, style.stroke, style.stroke-dashfill, stroke, dash
shape: rectangle, shape: squarea box
shape: cylindera cylinder
shape: circle, shape: ovala disc
direction: rightthe layered layout, already the default
the root’s labelthe title, drawn top-left; d2 itself never draws it
  • Keys match case-insensitively, repeated keys merge with the last write winning, and an edge to an undeclared name declares it, as in d2.
  • d2’s 17 other style keys (opacity, font-size, shadow, …) are accepted and not drawn. A misspelt style key is a warning.

Ignored, with a warning

  • variables other than vars.svugy, ${…} substitutions, imports (@…), class, classes, layers, scenarios, steps
  • globs and filters (*, &, !&), edge references ((a -> b)[0]), block strings (|md … |), arrays outside the carrier, null deletions
  • icon, constraint, near, width, height, top, left, grid-rows, grid-columns, grid-gap, vertical-gap, horizontal-gap, source-arrowhead, target-arrowhead
  • sub-keyed fields such as label.near or a.vars.svugy.caption
  • shapes other than those above; sql_table, sequence_diagram, class and hierarchy included
  • direction other than right, since svugy’s layered layout ranks along one axis
  • the arrowheads of <-> and --: the edge is kept, drawn from left operand to right
  • shape, direction and link on an edge; declarations inside an edge’s map
  • fields on the root other than label, direction and vars

The vars: { svugy: { … } } carrier

d2 has no syntax for what svugy draws beyond 2D boxes, and vars is the only map d2 accepts extra keys in: an unknown style.* key is a d2 compile error, and a dotted name like iso.depth declares child shapes.

On a shape:

KeyValueWhy not plain d2
captiontextd2 has no caption
shapebox, slab, cylinder, disc, any cased2 has no slab or explicit box; overrides d2’s shape
heightnumber, plan unitsd2’s height is a 2D size in pixels, and is ignored
position: { x; y }numbers, negative allowedd2’s top and left take non-negative integers, and only the TALA layout reads them
badgetrue or falsed2 has no badges; true badges every edge into this leaf from a leaf

On the root:

KeyValue
subtitletext
legend.titletext
legend.entrieslist of lines: ["① …"; "② …"]
legend.dashesmap of stroke-dash value to description: { 5: data; 2: build time }
legend.badgesmap of a badge target’s path to description: { data.cache: looks up the cache }
  • Any other key in the carrier is an error, with its location; d2 itself drops vars unread, so it never catches a typo there.
  • position needs x and y in one vars map, although d2 merges vars across statements.
  • d2’s own vars.d2-legend draws sample shapes, not text: it is ignored like any other variable.
  • A vars map on an edge is an error, even one without svugy, as d2 rejects it (“does not accept composite”).

What d2 can’t say

FeatureIn d2In Markdown
travelersimpossible: an edge can’t hold varstraveler=
one badge per edgebadge: true badges every edge into the leaf; on a container it is ignored with a warningline=badge on each edge
grid, row, column layoutsgrid-rows, grid-columns are ignoredlayout, columns
detail panel linesno place for themmeta.NAME
shared stylesclasses are ignored, so each shape repeats its style.fillfrontmatter styles

Import to Markdown

svugy import my.d2 -o my.md
  • The model keeps no named styles, so every property is written out and fills repeat as in d2. Factor them into frontmatter styles by hand.
  • If any part can’t be written as Markdown, import lists every such part, writes nothing and exits 1. Examples:
    • a key that isn’t a Markdown ID, e.g. one holding a space or a dot
    • a stroke-dash other than 0 (line=solid), 5 (line=dashed) or 2 (line=dotted)
    • any style key other than fill, stroke and stroke-dash
    • a label with a line break or leading or trailing whitespace

Next: Rust