d2

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package d2 provides server-side helpers for compiling D2 diagrams into SVG.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyDiagram is returned when the supplied diagram body is empty.
	ErrEmptyDiagram = errors.New("empty d2 diagram")
)

Functions

This section is empty.

Types

type Options

type Options struct {
	Timeout time.Duration
}

Options configure the renderer.

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer performs server-side D2 compilation using the embedded D2 compiler. Layout choices are left entirely to the source diagram (via D2 config blocks) or environment variables such as D2_LAYOUT.

func New

func New(_ context.Context, logger *slog.Logger, opts *Options) (*Renderer, error)

New creates a renderer instance. The provided context is unused for now but kept for API parity with future enhancements.

func (*Renderer) Render

func (r *Renderer) Render(ctx context.Context, source string) (Result, error)

Render compiles the given D2 script into SVG, respecting any layout directives defined inside the document itself.

type Result

type Result struct {
	SVG      string
	Duration time.Duration
}

Result captures the outcome of a render attempt.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL