Documentation
¶
Overview ¶
Package d2render renders a D2 diagram source to SVG in the platform (#2302), with D2's own Go library and its dagre layout.
It renders on the server because D2's browser build loads its layout engine with new Function in a blob: worker, which the share viewer's policy does not allow, and the same SVG then serves the asset page, both kinds of share link, the tile and the PDF alike. A source is held to the save-time check (internal/sourcecheck) before it is stored, so the render sees no import and no URL other than a managed resource's.
A render runs dagre's JavaScript inside goja, the Go JavaScript runtime D2 uses; the diagram source is never script. Each render is bounded by the source size, a timeout and how many run at once, and a rendered diagram is kept by its source's hash so a page viewed again does not render again.
Index ¶
Constants ¶
const ( // MaxSourceBytes is the largest source rendered. MaxSourceBytes = 256 << 10 // MaxSVGBytes is the largest drawing returned. MaxSVGBytes = 16 << 20 // Timeout bounds one render. Timeout = 10 * time.Second )
Variables ¶
var ErrTimeout = errors.New("d2render: the diagram did not finish rendering in time")
ErrTimeout is returned for a render that did not finish in time.
var ErrTooLarge = errors.New("d2render: the diagram is too large to render")
ErrTooLarge is returned for a source or drawing past its bound.
Functions ¶
func Serve ¶
Serve answers ?render=svg on a content route for a D2 source with the SVG rendered from it (&theme=dark for the dark drawing), and reports whether it answered. The source is the one the route already read and authorized, its references rewritten, so an icon names the reference route. The drawing is served through blobserve like any stored SVG: an attachment under the sandbox policy, which the portal reads as text and cleans before drawing.
Types ¶
This section is empty.