d2/ci/release/template/man/d2.1
2025-03-11 23:51:46 +05:30

225 lines
6.3 KiB
Groff

.Dd $Mdocdate$
.Dt d2 1
.Os
.Sh NAME
.Nm d2
.Nd compiles and renders d2 diagrams into svgs.
.Sh SYNOPSIS
.Nm d2
.Op Fl -watch Ar false
.Op Fl -theme Em 0
.Op Fl -salt Ar string
.Ar file.d2
.Op Ar file.svg | file.png
.Nm d2
.Ar layout Op Ar name
.Nm d2
.Ar fmt Ar file.d2 ...
.Nm d2
.Ar play Ar file.d2
.Nm d2
.Ar validate Ar file.d2
.Sh DESCRIPTION
.Nm
compiles and renders
.Ar file.d2
to
.Ar file.svg
|
.Ar file.png
.Ns .
.Pp
It defaults to
.Ar file.svg
if no output path is passed.
.Pp
Pass - to have
.Nm
read from stdin or write to stdout.
.Pp
Never use the presence of the output file to check for success.
Always use the exit status of
.Nm d2
.Ns .
This is because sometimes when errors occur while rendering, d2 still write out a partial
render anyway to enable iteration on a broken diagram.
.Pp
See more docs, the source code and license at
.Lk https://oss.terrastruct.com/d2
.Ns .
.Pp
Hosted icons at
.Lk https://icons.terrastruct.com
.Ns .
.Pp
Playground runner at
.Lk https://play.d2lang.com
.Ns .
.Sh OPTIONS
.Bl -tag -width Fl
.It Fl w , -watch Ar false
Watch for changes to input and live reload. Use
.Ev $PORT and Ev $HOST to specify the listening address.
.It Fl h , -host Ar localhost
Host listening address when used with
.Ar watch
.Ns .
.It Fl p , -port Ar 0
Port listening address when used with
.Ar watch
.Ns .
.It Fl t , -theme Ar 0
Set the diagram theme ID
.Ns .
.It Fl -dark-theme Ar -1
The theme to use when the viewer's browser is in dark mode. When left unset
.Fl -theme
is used for both light and dark mode. Be aware that explicit styles set in D2 code will
still be applied and this may produce unexpected results. We plan on resolving this by
making style maps in D2 light/dark mode specific. See
.Lk https://github.com/terrastruct/d2/issues/831
.Ns .
.It Fl s , -sketch Ar false
Renders the diagram to look like it was sketched by hand
.Ns .
.It Fl -center Ar flag
Center the SVG in the containing viewbox, such as your browser screen
.Ns .
.It Fl -scale Ar -1
Scale the output. E.g., 0.5 to halve the default size. Default -1 means that SVG's will fit to screen and all others will use their default render size. Setting to 1 turns off SVG fitting to screen
.Ns .
.It Fl -font-regular
Path to .ttf file to use for the regular font. If none provided, Source Sans Pro Regular is used
.Ns .
.It Fl -font-italic
Path to .ttf file to use for the italic font. If none provided, Source Sans Pro Regular-Italic is used
.Ns .
.It Fl -font-bold
Path to .ttf file to use for the bold font. If none provided, Source Sans Pro Bold is used
.Ns .
.It Fl -pad Ar 100
Pixels padded around the rendered diagram
.Ns .
.It Fl -animate-interval Ar 0
If given, multiple boards are packaged as 1 SVG which transitions through each board at the interval (in milliseconds). Can only be used with SVG and GIF exports
.Ns .
.It Fl -browser Ar true
Browser executable that watch opens. Setting to 0 opens no browser
.Ns .
.It Fl l , -layout Ar dagre
Set the diagram layout engine to the passed string. For a list of available options, run
.Ar layout
.Ns .
.It Fl b , -bundle Ar true
Bundle all assets and layers into the output svg
.Ns .
.It Fl -force-appendix Ar false
An appendix for tooltips and links is added to PNG exports since they are not interactive. Setting this to true adds an appendix to SVG exports as well
.Ns .
.It Fl -target
Target board to render. Pass an empty string to target root board. If target ends with '*', it will be rendered
with all of its scenarios, steps, and layers. Otherwise, only the target board will be rendered. E.g. --target=''
to render root board only or --target='layers.x.*' to render layer 'x' with all of its children
.Ns .
.It Fl d , -debug
Print debug logs
.Ns .
.It Fl -img-cache Ar true
In watch mode, images used in icons are cached for subsequent compilations. This should be disabled if images might change
.Ns .
.It Fl -timeout Ar 120
The maximum number of seconds that D2 runs for before timing out and exiting. When rendering a large diagram, it is recommended to increase this value
.Ns .
.It Fl -check Ar false
Check that the specified files are formatted correctly
.Ns .
.It Fl -salt Ar string
Add a salt value to ensure the output uses unique IDs. This is useful when generating multiple identical diagrams to be included in the same HTML doc, so that duplicate id's do not cause invalid HTML. The salt value is a string that will be appended to IDs in the output.
.Ns .
.It Fl h , -help
Print usage information and exit
.Ns .
.It Fl v , -version
Print version information and exit
.Ns .
.It Fl -stdout-format Ar string
Set the output format when writing to stdout. Supported formats are: png, svg. Only used when output is set to stdout (-)
.Ns .
.It Fl -no-xml-tag Ar false
Omit XML tag (<?xml ...?>) from output SVG files. Useful when generating SVGs for direct HTML embedding
.Ns .
.El
.Sh SUBCOMMANDS
.Bl -tag -width Fl
.It Ar layout
Lists available layout engine options with short help
.Ns .
.It Ar layout Op Ar name
Display long help for a particular layout engine, including its configuration options
.Ns .
.It Ar themes
Lists available themes
.Ns .
.It Ar fmt Ar file.d2 ...
Format all passed files
.It Ar play Ar file.d2
Opens the file in playground, an online web viewer (https://play.d2lang.com)
.It Ar validate Ar file.d2
Validates file.d2
.El
.Sh ENVIRONMENT VARIABLES
Many flags can also be set with environment variables.
.Bl -tag -width Ds
.It Ev Sy D2_WATCH
See -w[atch] flag.
.It Ev Sy D2_LAYOUT
See -l[ayout] flag.
.It Ev Sy D2_THEME
See -t[heme] flag.
.It Ev Sy D2_DARK_THEME
See --dark-theme flag.
.It Ev Sy D2_PAD
See --pad flag.
.It Ev Sy D2_CENTER
See --center flag.
.It Ev Sy D2_SKETCH
See -s[ketch] flag.
.It Ev Sy D2_BUNDLE
See -b[undle] flag.
.It Ev Sy D2_FORCE_APPENDIX
See --force-appendix flag.
.It Ev Sy D2_FONT_REGULAR
See --font-regular flag.
.It Ev Sy D2_FONT_ITALIC
See --font-italic flag.
.It Ev Sy D2_FONT_BOLD
See --font-bold flag.
.It Ev Sy D2_FONT_SEMIBOLD
See --font-semibold flag.
.It Ev Sy D2_ANIMATE_INTERVAL
See --animate-interval flag.
.It Ev Sy D2_TIMEOUT
See --timeout flag.
.It Ev Sy D2_CHECK
See --check flag.
.El
.Bl -tag -width Ds
.It Ev Sy DEBUG
See -d[ebug] flag.
.It Ev Sy IMG_CACHE
See --img-cache flag.
.It Ev Sy HOST
See -h[ost] flag.
.It Ev Sy PORT
See -p[ort] flag.
.It Ev Sy BROWSER
See --browser flag.
.It Ev Sy D2_STDOUT_FORMAT
See --stdout-format flag.
.It Ev Sy D2_NO_XML_TAG
See --no-xml-tag flag.
.El
.Sh SEE ALSO
.Xr d2plugin-tala 1
.Sh AUTHORS
Terrastruct Inc.