Help us shape the future of Go! Take the 2026 Go Developer Survey

core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package core turns a inkline source file into plain D2: it expands per-diagram shorthand and gives every object and connection a semantic role (see spec/roles.md). It knows nothing about how roles look; that is the design system's job.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiagramNames

func DiagramNames() []string

DiagramNames lists the supported diagram types, sorted.

Types

type File

type File struct {
	Source
	Header Header
	Spec   *Spec
	// contains filtered or unexported fields
}

File is a parsed inkline file.

func Parse

func Parse(src Source) (*File, error)

Parse parses a inkline file and reads its header.

func (*File) Expand

func (f *File) Expand(prelude string) (string, error)

Expand returns plain D2: prelude, the author's (transformed) source, and a role overlay that gives every object and connection its role.

The prelude comes from the design system; it is compiled together with the source so the overlay sees the final shapes (a class may set shape: sql_table).

type Header struct {
	Diagram      string
	DesignSystem string
	Theme        string
	// Orientation applies to swimlanes: vertical (default; lanes are columns)
	// or horizontal (lanes are rows).
	Orientation string
}

Header is the inkline block of a file's vars:

vars: { inkline: { diagram: flowchart; design_system: carbon; theme: light } }

func ReadHeader

func ReadHeader(ast *d2ast.Map) (Header, error)

ReadHeader reads and validates the inkline header from a parsed file.

func (*Header) Override

func (h *Header) Override(designSystem, theme string) error

Override replaces the design system and theme, where given, and validates the result.

type Source

type Source struct {
	// Path is the file's path. Imports resolve against its directory within
	// FS, or on disk when FS is nil.
	Path string
	FS   fs.FS
	Text string
}

Source is one inkline file to expand.

type Spec

type Spec struct {
	Name       string
	Nodes      []string
	Containers []string
	Edges      []string
	// TopLevelOnly limits object roles to top-level objects, for diagrams whose
	// nested keys are not objects (class fields, table columns, sequence spans).
	TopLevelOnly bool
	// Layout is the layout engine used unless the file or design system says otherwise.
	Layout string
	// AnalysisShape is given to every top-level object while the core compiles the
	// source to find its objects. Diagrams whose keys only compile inside a
	// structural shape (sql_table columns with constraints) need it; the final
	// shape comes from the role's class.
	AnalysisShape string
	// DefaultRole, when set, overrides the default-role rule for objects.
	DefaultRole func(obj *d2graph.Object) string
	// Transform expands the diagram's shorthand, writing the D2 to compile.
	// Nil writes the source as it is.
	Transform func(ast *d2ast.Map, b *body) error
	// Settings is D2 that applies to the diagram as a whole.
	Settings string
	// Skip reports objects that take no role.
	Skip func(obj *d2graph.Object) bool
	// Annotate returns further D2 for an object, given its key and role.
	Annotate func(obj *d2graph.Object, id, role string) string
	// Lanes lays the diagram out as a matrix of lanes and ranks (see
	// laneLayout); its connections need the lane router.
	Lanes bool
}

Spec describes one diagram type. The first role of each list is the default.

func Lookup

func Lookup(name string) (*Spec, bool)

Lookup returns the spec for a diagram type.

Jump to

Keyboard shortcuts

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