docir

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package docir evaluates compiled document plans into an immutable, backend-agnostic document tree with provenance on every node.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnchorFor

func AnchorFor(path []string) string

AnchorFor derives a content node's stable anchor from its named path: segments joined by "-", with every byte outside [A-Za-z0-9_] encoded as "." and two uppercase hex digits, so distinct paths never collide.

Types

type Content

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

Content is one evaluated content node: a section, paragraph, table, list, definitions block, formula, diagram, or image.

func (Content) Alt added in v0.9.2

func (c Content) Alt() string

Alt returns the text alternative an image states, empty for none.

func (Content) Anchor

func (c Content) Anchor() string

Anchor returns the node's stable identifier when a reference run targets it, empty otherwise.

func (Content) Caption

func (c Content) Caption() string

Caption returns the caption of a table, formula, diagram or image.

func (Content) Children

func (c Content) Children() []Content

Children returns the nested content of a section in declaration order.

func (Content) Columns

func (c Content) Columns() []queryexec.Column

Columns returns the ordered projected columns of a table, preserved even when the query returned no rows.

func (Content) Definitions

func (c Content) Definitions() []Definition

Definitions returns the ordered entries of a definitions block.

func (Content) Direction

func (c Content) Direction() view.Direction

Direction returns the stated flow direction of a diagram, empty for the kind's default.

func (Content) File added in v0.9.2

func (c Content) File() string

File returns the file on disk an image block was declared in, which its relative location is stated against; "" when it was declared in none.

func (Content) GroupBy

func (c Content) GroupBy() string

GroupBy returns the projected column a table groups its rows by, empty when ungrouped.

func (Content) Groups

func (c Content) Groups() []TableGroup

Groups returns the ordered row groups of a grouped table.

func (Content) Items

func (c Content) Items() []ListItem

Items returns the ordered items of a list.

func (Content) Kind

func (c Content) Kind() ContentKind

Kind returns the classification of the node.

func (Content) Location added in v0.9.2

func (c Content) Location() string

Location returns the path or URL an image shows.

func (Content) Name

func (c Content) Name() string

Name returns the declared name of the node, empty when anonymous.

func (Content) Options

func (c Content) Options() view.Options

Options returns what a diagram's rendering is written with: its stated direction and palette.

func (Content) Origin

func (c Content) Origin() symbols.Origin

Origin returns the source declaration behind the node.

func (Content) Palette

func (c Content) Palette() view.Palette

Palette returns the stated palette of a diagram, empty for black and white.

func (Content) Ports added in v0.10.0

func (c Content) Ports() view.Ports

Ports returns the stated port display of a diagram, empty for the default, minimal.

func (Content) Query

func (c Content) Query() string

Query returns the fully-qualified name of the query behind a query-backed node, empty for sections and static paragraphs.

func (Content) QueryOrigin

func (c Content) QueryOrigin() symbols.Origin

QueryOrigin returns the declaration of the query behind a query-backed node.

func (Content) Rendering

func (c Content) Rendering() *view.Rendering

Rendering returns a copy of the resolved view content of a diagram, nil for every other kind.

func (Content) Rows

func (c Content) Rows() []queryexec.Row

Rows returns the ordered rows of a table with their typed cells.

func (Content) Runs

func (c Content) Runs() []TextRun

Runs returns the text runs of a paragraph in row and column order.

func (Content) Sites added in v0.10.0

func (c Content) Sites() view.Sites

Sites returns the source locations diagrams in this content link to.

func (Content) Source

func (c Content) Source() string

Source returns the LaTeX source of a formula, typeset as display mathematics, or the location an image block shows: a path relative to the document's source file, or a URL.

func (Content) Style

func (c Content) Style() ListStyle

Style returns the style of a list.

func (Content) Title

func (c Content) Title() string

Title returns the title of a section.

type ContentKind

type ContentKind string

ContentKind classifies one evaluated content node.

const (
	ContentSection     ContentKind = "section"
	ContentParagraph   ContentKind = "paragraph"
	ContentTable       ContentKind = "table"
	ContentList        ContentKind = "list"
	ContentDefinitions ContentKind = "definitions"
	ContentFormula     ContentKind = "formula"
	ContentDiagram     ContentKind = "diagram"
	ContentImage       ContentKind = "image"
)

type Definition

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

Definition is one evaluated definitions entry, produced from one query row.

func (Definition) Description

func (d Definition) Description() []TextRun

Description returns the runs describing the entry, one per value of the description column.

func (Definition) Element

func (d Definition) Element() queryexec.Value

Element returns the model element the entry's query row selected.

func (Definition) Origin

func (d Definition) Origin() symbols.Origin

Origin returns the query row behind the entry.

func (Definition) Term

func (d Definition) Term() []TextRun

Term returns the runs naming the entry, one per value of the term column.

type Document

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

Document is an immutable evaluated document.

func Evaluate

func Evaluate(
	plan *docplan.Plan,
	context queryexec.Context,
	options queryexec.Options,
	text view.SourceText,
) (*Document, error)

Evaluate evaluates a compiled document plan into an immutable document, executing every referenced query through the query execution engine. text supplies notation labels to diagram renderings and may be nil.

func EvaluateLinked

func EvaluateLinked(
	plan *docplan.Plan,
	siblings []*docplan.Plan,
	context queryexec.Context,
	options queryexec.Options,
	text view.SourceText,
) (*Document, error)

EvaluateLinked evaluates one plan like Evaluate while also emitting the stable anchors the sibling documents' plans reference into it, so a document rendered on its own carries the anchors incoming cross-document links expect once the files share a directory.

func Unrendered added in v0.9.2

func Unrendered(name, title string, err error, siblings []*docplan.Plan) *Document

Unrendered is the document a set writes in place of the one named name, titled title, that could not be rendered: a paragraph stating why, then one carrying each anchor the siblings' plans link into it by, so every link into the document lands on the reason rather than on nothing.

func (*Document) Content

func (d *Document) Content() []Content

Content returns the evaluated top-level content in declaration order.

func (*Document) ElementName added in v0.9.2

func (d *Document) ElementName(sym *symbols.Symbol) string

ElementName is the name an element value of the document is displayed by: its effective name in the model the document was evaluated in, else its qualified name.

func (*Document) Name

func (d *Document) Name() string

Name returns the fully-qualified name of the document definition.

func (*Document) Origin

func (d *Document) Origin() symbols.Origin

Origin returns the source declaration behind the document.

func (*Document) Title

func (d *Document) Title() string

Title returns the document title.

type Error

type Error struct {
	Kind     ErrorKind
	Document string
	Content  string
	Query    string
	Column   string
	Row      int
	Actual   string
	Origin   symbols.Origin
	Err      error
}

Error is a typed document-evaluation failure with its source location.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying execution or rendering failure, if any.

type ErrorKind

type ErrorKind string

ErrorKind classifies a document-evaluation failure.

const (
	ErrorInvalidContext          ErrorKind = "invalid-context"
	ErrorInvalidPlan             ErrorKind = "invalid-plan"
	ErrorQueryExecution          ErrorKind = "query-execution"
	ErrorViewRendering           ErrorKind = "view-rendering"
	ErrorUnknownGroup            ErrorKind = "unknown-group-column"
	ErrorUnknownRunColumn        ErrorKind = "unknown-run-column"
	ErrorInvalidRunStyle         ErrorKind = "invalid-run-style"
	ErrorInvalidRunTarget        ErrorKind = "invalid-run-target"
	ErrorBlankMath               ErrorKind = "blank-math"
	ErrorUnknownDefinitionColumn ErrorKind = "unknown-definition-column"
	ErrorMissingImageLocation    ErrorKind = "missing-image-location"
	// ErrorValueEvaluation: a value run's feature could not be read.
	ErrorValueEvaluation ErrorKind = "value-evaluation"
	// ErrorEmptyValue: a value run's feature has no value to render.
	ErrorEmptyValue ErrorKind = "empty-value"
)

type Evaluated added in v0.9.2

type Evaluated struct {
	Name     string
	Document *Document
	Err      error
}

Evaluated is the outcome of evaluating one plan of a set: the document, or under Err the error that kept the plan named Name from evaluating.

func EvaluateSet

func EvaluateSet(
	plans []*docplan.Plan,
	context queryexec.Context,
	options queryexec.Options,
	text view.SourceText,
) ([]Evaluated, error)

EvaluateSet evaluates a set of compiled document plans together, so a content block one document references from another carries its anchor in the rendered target document. Each plan evaluates on its own: one that fails leaves the others' documents whole and is reported in its outcome. A plan that is not compiled fails the set.

type ListItem

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

ListItem is one evaluated list item, produced from one query row.

func (ListItem) Element

func (i ListItem) Element() queryexec.Value

Element returns the model element the item's query row selected.

func (ListItem) Origin

func (i ListItem) Origin() symbols.Origin

Origin returns the query row behind the item.

func (ListItem) Runs

func (i ListItem) Runs() []TextRun

Runs returns the item's text runs in column order.

type ListStyle

type ListStyle string

ListStyle is the rendering style of an evaluated list.

const (
	ListBullet ListStyle = "bullet"
	ListNumber ListStyle = "number"
)

type RunKind

type RunKind string

RunKind classifies one text run: plain prose, an inline style, inline mathematics, a link to an external destination, or a reference to another content node.

const (
	RunPlain    RunKind = "plain"
	RunEmphasis RunKind = "emphasis"
	RunStrong   RunKind = "strong"
	RunCode     RunKind = "code"
	// RunMath is inline mathematics; the run's text is LaTeX source.
	RunMath RunKind = "math"
	RunLink RunKind = "link"
	RunRef  RunKind = "ref"
)

type TableGroup

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

TableGroup is one group of a grouped table's rows sharing a group-column value, in order of first appearance.

func (TableGroup) Key

func (g TableGroup) Key() string

Key returns the shared group-column text of the group's rows.

func (TableGroup) Rows

func (g TableGroup) Rows() []queryexec.Row

Rows returns the group's rows in result order.

type TextRun

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

TextRun is one piece of paragraph or list-item text with its provenance: static text carries its declaration, query-backed text its query value.

func (TextRun) Bound added in v0.12.0

func (r TextRun) Bound() bool

Bound reports whether the run's text already carries its spacing to the neighbouring runs, so a backend joins it to them without a separator.

func (TextRun) Kind

func (r TextRun) Kind() RunKind

Kind returns the classification of the run; the zero value is plain.

func (TextRun) Origin

func (r TextRun) Origin() symbols.Origin

Origin returns the source declaration or query value behind the run.

func (TextRun) Target

func (r TextRun) Target() string

Target returns a link run's destination, or a reference run's anchor — the stable identifier of the referenced content node. A reference to another document's root has no anchor.

func (TextRun) TargetDocument

func (r TextRun) TargetDocument() string

TargetDocument returns the fully-qualified name of the document a reference run targets, or "" when it targets its own document.

func (TextRun) TargetElement added in v0.10.0

func (r TextRun) TargetElement() string

TargetElement returns the fully-qualified name of the model element a reference run targets when that is neither a content block nor a document — a reference no document gives an anchor — or "" when it is one.

func (TextRun) Text

func (r TextRun) Text() string

Text returns the run's text.

func (TextRun) TextDefaulted added in v0.10.0

func (r TextRun) TextDefaulted() bool

TextDefaulted reports whether a reference run's text is its target's label, the run stating none: a renderer numbering its sections or figures may label the target by its number instead.

Jump to

Keyboard shortcuts

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