docrender

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: 22 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 docrender renders evaluated documents into backend-specific artifacts, consuming only the document IR — never plans, symbols, or ASTs.

Index

Constants

View Source
const (
	WideTableColumns  = 7
	DenseTableColumns = 11
)

WideTableColumns and DenseTableColumns mark tables for the print and Pandoc stylesheets to select by class.

View Source
const DefaultTheme = "default"

DefaultTheme names the default stylesheet on its own.

View Source
const GraphvizFallbackNotice = "drawn as Mermaid, not at its stated positions: Graphviz (dot) is not installed"

GraphvizFallbackNotice is the emphasized paragraph written between a positioned diagram's caption and its Mermaid source when no Graphviz drew it.

View Source
const MathScriptURL = "https://cdn.jsdelivr.net/npm/mathjax@3.2.2/es5/tex-mml-chtml.js"

MathScriptURL is the pinned MathJax release a page loads from a public CDN when a math script is asked for by name rather than URL.

View Source
const MermaidScriptURL = "https://cdn.jsdelivr.net/npm/mermaid@11.16.1/dist/mermaid.min.js"

MermaidScriptURL is the pinned Mermaid release a page loads from a public CDN when a script is asked for by name rather than URL.

View Source
const StylesheetFileName = "sysml-document.css"

StylesheetFileName is the file a rendered document set links its shared stylesheet from.

Variables

This section is empty.

Functions

func AsciiDoc added in v0.12.0

func AsciiDoc(document *docir.Document, opts AsciiDocOptions) (string, error)

AsciiDoc renders an evaluated document as AsciiDoc: the title as the document title, sections as section titles by depth, and every other content kind as the block AsciiDoc has for it, under its caption as a block title. Diagrams are drawn as Markdown draws them (see Markdown); a document with math declares `:stem: latexmath` in its header so stem macros and blocks read as LaTeX.

func AsciiDocFileName added in v0.12.0

func AsciiDocFileName(fqn string) string

AsciiDocFileName is the AsciiDoc file a document is written to on its own, DocumentFileStem of its qualified name plus `.adoc`.

func Captions

func Captions(document *docir.Document, numbered bool) []string

Captions lists the document's table, diagram, formula and image captions in document order: each is the emphasized paragraph the Markdown backend writes ahead of its block, for a consumer telling a caption from a paragraph that happens to be emphasized. Each is listed as written, without surrounding blanks; a blank caption is written nowhere and listed nowhere. With numbered set, as MarkdownOptions.NumberFigures, the figures and tables are listed with their numbers, a block without a caption by its number alone.

func DefaultStylesheet

func DefaultStylesheet() string

func DocumentFileName

func DocumentFileName(fqn string) string

DocumentFileName is the Markdown file a document is written to on its own, DocumentFileStem of its qualified name plus `.md`.

func DocumentFileStem added in v0.9.2

func DocumentFileStem(fqn string) string

DocumentFileStem is the file name, extension aside, a document derives from its qualified name: `::` as `-` and every byte outside ASCII letters, digits and `_` as `.XX`, the encoding of anchors. A stem naming a Windows device has its first byte encoded too, and one opening with `.` is prefixed `_`, so the file is neither a device nor hidden. A set fits and tags the stems it writes.

func DocumentHTMLFileName

func DocumentHTMLFileName(fqn string) string

DocumentHTMLFileName is the HTML file a document is written to on its own, DocumentFileStem of its qualified name plus `.html`.

func HTML

func HTML(document *docir.Document, opts HTMLOptions) (string, error)

HTML renders an evaluated document as deterministic, semantic HTML: an <article> holding nested <section> elements, real tables with <caption> and <th scope>, <ul>/<ol> lists, <dl> definitions, <figure> formulas holding their LaTeX in display delimiters and <figure> diagrams carrying their source in the chosen diagram form. Every node keeps its model facts in sysml- classes and data- attributes — content kind, declared name, query, group column, row element and its kind, projected column, value kind, reference target, diagram kind, direction and palette — and every value is escaped so no content can corrupt the structure.

func Markdown

func Markdown(document *docir.Document, opts MarkdownOptions) (string, error)

Markdown renders an evaluated document as deterministic CommonMark: the title as a level-1 ATX heading, each section one level deeper (saturating at 6), paragraphs from space-joined text runs, GitHub-flavored pipe tables with projected column headers, bullet or numbered lists, definitions as one "**term** — description" paragraph per entry, formulas as $$-fenced display math with inline math in $…$, and diagrams as fenced blocks of their source in the chosen diagram form (tabular views as pipe tables). Metacharacters in content are escaped so no value can corrupt the document structure; LaTeX is written verbatim, since math is not prose.

func StylesheetMarkup

func StylesheetMarkup(sheets []Stylesheet) string

StylesheetMarkup is the head markup attaching sheets in order: a linked sheet as a <link> element, an inline one as a <style> element.

func ThemePrintStylesheet

func ThemePrintStylesheet(name string) (string, error)

ThemePrintStylesheet is the named theme's print companion, the overrides a paged backend lays over its print stylesheet; empty for a theme without one.

func ThemeStylesheet

func ThemeStylesheet(name string) (string, error)

ThemeStylesheet is the default stylesheet followed by the named theme's overrides in the same layer; empty or DefaultTheme is the default alone.

func Themes

func Themes() []string

Themes lists the bundled theme names, the default first and the rest sorted.

Types

type AsciiDocOptions added in v0.12.0

type AsciiDocOptions MarkdownOptions

AsciiDocOptions shape AsciiDoc output; each field means what it does for Markdown (see MarkdownOptions), the two backends writing the same document in two markups.

type Diagram

type Diagram struct {
	Name     string
	Form     view.Form
	Source   string
	Fallback string
}

Diagram is one graph-shaped diagram of a document: its declared name, the form it is written in, its source in that form, and, when the form is the automatic choice's Mermaid fallback, the reason stated in the output.

func Diagrams

func Diagrams(document *docir.Document, opts DiagramOptions) ([]Diagram, error)

Diagrams lists the document's graph-shaped diagrams in document order, each with the source the backends write for it as opts says. A tabular view is a table, not a diagram, and is left out.

type DiagramDrawer added in v0.9.2

type DiagramDrawer interface {
	// Available reports whether Graphviz is installed to draw with.
	Available() bool
	// Draw is the SVG of each DOT diagram, in order, empty for the others.
	Draw(diagrams []Diagram) ([]string, error)
}

DiagramDrawer draws a document's DOT diagrams to SVG ahead of a render, for the HTML and Markdown backends to write inline where the automatic choice picks DOT; the PDF backend's Graphviz is one.

type DiagramOptions added in v0.9.2

type DiagramOptions struct {
	// Form is the form every diagram is written in; empty picks per diagram:
	// DOT for a rendering a Layout or Route positions, Mermaid otherwise.
	Form view.Form

	// WithoutGraphviz records that no Graphviz draws DOT for this render, so
	// the automatic choice falls back to Mermaid for positioned diagrams too,
	// stating so in the output. An explicit Form is written regardless.
	WithoutGraphviz bool

	// Unplaced is where a diagram some Layout positions puts the nodes none
	// does: left undrawn when empty, or drawn too (a strip below a DOT drawing).
	Unplaced view.Unplaced
	// Compartments is how a tree rendering folds a node's owned members into
	// compartment rows of its box; view.CompartmentsPositioned when empty.
	Compartments view.Compartments

	// Style is the drawing style every DOT or Mermaid diagram is drawn in, the
	// Pilot look when empty; the other forms draw one look.
	Style view.DrawingStyle

	// Show is the optional notation elements every diagram draws besides the
	// ones its view's rendering shows; nil adds none.
	Show view.Shown

	// LinkTemplate fills source links for diagram elements.
	LinkTemplate string
}

DiagramOptions is how a render writes its graph-shaped diagrams: the part of MarkdownOptions and HTMLOptions Diagrams lists them by.

type Error

type Error struct {
	Kind    ErrorKind
	Content string
	Actual  string
	// DiagramForm is the diagram form asked for, when a failure is about one.
	DiagramForm view.Form
	// Form is the backend that failed, "Markdown" when empty.
	Form string
	// Count is how many of something the document has, when a failure is about
	// a mismatch with it.
	Count int
	// TextSize and Edges size the chart an oversized diagram writes.
	TextSize, Edges int
}

Error is a typed document-rendering failure.

func (*Error) Error

func (e *Error) Error() string

type ErrorKind

type ErrorKind string

ErrorKind classifies a document-rendering failure.

const (
	ErrorNilDocument         ErrorKind = "nil-document"
	ErrorUnknownContent      ErrorKind = "unknown-content"
	ErrorMissingRendering    ErrorKind = "missing-rendering"
	ErrorUnrenderableDiagram ErrorKind = "unrenderable-diagram"
	ErrorUnrenderableForm    ErrorKind = "unrenderable-diagram-form"
	ErrorUnknownForm         ErrorKind = "unknown-diagram-form"
	// ErrorOversizedDiagram is a Mermaid chart past the size a chart is drawn under.
	ErrorOversizedDiagram    ErrorKind = "oversized-diagram"
	ErrorEmptyStylesheet     ErrorKind = "empty-stylesheet"
	ErrorAmbiguousStylesheet ErrorKind = "ambiguous-stylesheet"
	ErrorUnsafeStylesheet    ErrorKind = "unsafe-stylesheet"
	ErrorUnknownTheme        ErrorKind = "unknown-theme"
	// ErrorSurplusDiagramImages is more diagram images than the document has
	// graph-shaped diagrams to write them for.
	ErrorSurplusDiagramImages ErrorKind = "surplus-diagram-images"
	// ErrorTableColumns is a table-column limit no continuation table keeps:
	// one leaves no room beside the repeated first column.
	ErrorTableColumns ErrorKind = "table-columns"
)

type Formula

type Formula struct {
	Source  string
	Display bool
}

Formula is one formula of a document as the HTML backend keys it: its LaTeX source, trimmed, and whether it is displayed on a line of its own.

func Formulas

func Formulas(document *docir.Document) []Formula

Formulas lists the document's distinct formulas in document order: every math run of its paragraphs, list items and definitions, and every formula block. Each key is one HTMLOptions.Math may carry typeset HTML for.

func (Formula) TeX

func (f Formula) TeX() string

TeX is the formula as a TeX engine reads it and as the Markdown backend writes it between its delimiters: trimmed, blank lines dropped, a bare dollar escaped so it typesets as a dollar rather than closing math mode.

type HTMLOptions

type HTMLOptions struct {
	// Fragment writes the document element alone, without the page shell or
	// any stylesheet, for embedding in a host page.
	Fragment bool

	// NoDefaultStylesheet leaves the default stylesheet out.
	NoDefaultStylesheet bool

	// Theme names the bundled theme layered over the default stylesheet;
	// empty is the default alone. Ignored with NoDefaultStylesheet.
	Theme string

	// Stylesheets are attached after the default one, unlayered, so their
	// declarations win on cascade origin rather than on specificity.
	Stylesheets []Stylesheet

	// TitlePage puts the document title in a page of its own.
	TitlePage bool

	// TOC writes a table of contents ahead of the content.
	TOC bool

	// NumberSections numbers the section headings hierarchically.
	NumberSections bool

	// NumberFigures numbers figures and tables as MarkdownOptions.NumberFigures,
	// the label in a sysml-caption-number span.
	NumberFigures bool

	// Lang is the page language, "en" when empty.
	Lang string

	// MermaidScript is the URL of a Mermaid script a standalone page loads to
	// draw its diagrams; empty loads none, leaving each as source.
	MermaidScript string

	// MathScript is the URL of a MathJax-compatible script a standalone page
	// loads to typeset its formulas; empty loads none, leaving each as LaTeX
	// source in \(…\) or \[…\] delimiters.
	MathScript string

	// DiagramForm is the source every graph-shaped diagram is written as; a
	// a tabular view is a table whichever it is. Empty picks per diagram:
	// DOT for a rendering a Layout or Route positions, Mermaid otherwise.
	DiagramForm view.Form

	// WithoutGraphviz records that no Graphviz draws DOT for this render, so
	// the automatic choice writes Mermaid for positioned diagrams too, with a
	// notice stating so. An explicit DiagramForm is written regardless.
	WithoutGraphviz bool

	// Unplaced is where a diagram some Layout positions puts the nodes none
	// does: left undrawn when empty, or drawn too (a strip below a DOT drawing).
	Unplaced view.Unplaced
	// Compartments is how a tree rendering folds a node's owned members into
	// compartment rows of its box; view.CompartmentsPositioned when empty.
	Compartments view.Compartments

	// Style is the drawing style every DOT diagram is drawn in, the Pilot look
	// when empty; the other forms draw one look.
	Style view.DrawingStyle

	// Show is the optional notation elements every diagram draws besides the
	// ones its view's rendering shows; nil adds none.
	Show view.Shown

	// LinkTemplate fills source links for diagram elements. HTML content has no element-anchored sections.
	LinkTemplate string

	// Files is the file each document of the set this one is rendered in is
	// written to, by qualified name; a cross-document reference links to the
	// target's file here, or to DocumentHTMLFileName of its name when absent.
	Files map[string]string

	// DiagramImages are images drawn ahead of the render, one per graph-shaped
	// diagram in the order Diagrams lists them, each written as <img> in place
	// of its source; an empty entry, or none, keeps the source. More entries
	// than diagrams is an error.
	DiagramImages []string

	// DiagramSVG is SVG markup drawn ahead of the render, one per graph-shaped
	// diagram in the order Diagrams lists them, each written inline in place
	// of its source; an empty entry, or none, defers to DiagramImages, then
	// the source. More entries than diagrams is an error.
	DiagramSVG []string

	// Drawer draws the DOT diagrams the automatic choice picks, filling
	// DiagramSVG when that is empty; one that is not available settles the
	// choice on the Mermaid fallback. Nil leaves the choice to WithoutGraphviz.
	Drawer DiagramDrawer

	// Math is typeset HTML for formulas, keyed as Formulas lists them, written
	// in place of the delimited LaTeX; a formula with none keeps its LaTeX.
	Math map[Formula]string

	// OutputDir is the directory the page is written into, when known, so an
	// image's source-relative location is written relative to it; empty writes it as stated.
	OutputDir string

	// TableColumns is the most columns one table is written with: a table
	// projecting more is written as continuation tables, each repeating the
	// first column ahead of its share of the rest. 0 writes every table whole;
	// 1 is refused, as nothing would fit beside the repeated column.
	TableColumns int

	// TableMeasure is the characters of header type one table line holds.
	// When positive, a table is split into continuation tables so that every
	// part's headings fit unbroken at their columns' shares of the line, and a
	// sized part's shares widen to what its headings need. 0 splits by
	// TableColumns alone.
	TableMeasure int
}

HTMLOptions are the presentation choices of the HTML backend. They are options of this backend, never document-model attributes.

type Image added in v0.9.2

type Image struct {
	Name     string
	Location string
	Dir      string
	Alt      string
	Caption  string
}

Image is one image block of a document: its name, the location it shows, the directory of the source file stating that location ("" when the source is no file on disk), its alt text and caption.

func Images added in v0.9.2

func Images(document *docir.Document) []Image

Images lists the image blocks of a document in document order.

func (Image) Path added in v0.9.2

func (i Image) Path(base string) string

Path is the file a local location names: relative to the source file's directory, else to base; absolute paths and file URLs as written; "" when remote.

func (Image) Relative added in v0.9.2

func (i Image) Relative() bool

Relative reports a location that is a relative path: one stated relative to the document's source file, as DocumentQueries::Image documents.

func (Image) Remote added in v0.9.2

func (i Image) Remote() bool

Remote reports a location rendered where it stands: an http(s) URL an engine or browser fetches, or a data URL carrying the image itself.

func (Image) Source added in v0.9.2

func (i Image) Source(outputDir string) string

Source is how a rendering written into outputDir refers to the image: a source file's relative path made relative to outputDir; anything else as stated.

type MarkdownOptions

type MarkdownOptions struct {
	// DiagramForm is the source every graph-shaped diagram is written as; a
	// tabular view is a pipe table whichever it is. Empty picks per diagram:
	// DOT for a rendering a Layout or Route positions, Mermaid otherwise.
	DiagramForm view.Form

	// WithoutGraphviz records that no Graphviz draws DOT for this render, so
	// the automatic choice writes Mermaid for positioned diagrams too, with an
	// emphasised notice stating so. An explicit DiagramForm is written regardless.
	WithoutGraphviz bool

	// Unplaced is where a diagram some Layout positions puts the nodes none
	// does: left undrawn when empty, or drawn too (a strip below a DOT drawing).
	Unplaced view.Unplaced
	// Compartments is how a tree rendering folds a node's owned members into
	// compartment rows of its box; view.CompartmentsPositioned when empty.
	Compartments view.Compartments

	// Style is the drawing style every DOT diagram is drawn in, the Pilot look
	// when empty; the other forms draw one look.
	Style view.DrawingStyle

	// Show is the optional notation elements every diagram draws besides the
	// ones its view's rendering shows; nil adds none.
	Show view.Shown

	// LinkTemplate fills source links for diagram elements.
	LinkTemplate string

	// Files is the file each document of the set this one is rendered in is
	// written to, by qualified name; a cross-document reference links to the
	// target's file here, or to DocumentFileName of its name when absent.
	Files map[string]string

	// DiagramSVG is SVG markup drawn ahead of the render, one per graph-shaped
	// diagram in the order Diagrams lists them, each written as an HTML block
	// in place of its fenced source; an empty entry, or none, keeps the fence.
	// More entries than diagrams is an error.
	DiagramSVG []string

	// Drawer draws the DOT diagrams the automatic choice picks, filling
	// DiagramSVG when that is empty; one that is not available settles the
	// choice on the Mermaid fallback. Nil leaves the choice to WithoutGraphviz.
	Drawer DiagramDrawer

	// OutputDir is the directory the document is written into, when known, so an
	// image's source-relative location is written relative to it; empty writes it as stated.
	OutputDir string

	// NumberFigures captions figures (drawn diagrams, images) "Figure N. …" and
	// tables (query tables, tabular diagrams) "Table N. …" in document order.
	NumberFigures bool

	// TableColumns is the most columns one pipe table is written with: a table
	// projecting more is written as continuation tables, each repeating the
	// first column ahead of its share of the rest. 0 writes every table whole;
	// 1 is refused, as nothing would fit beside the repeated column.
	TableColumns int

	// TableMeasure is the characters of header type one table line holds.
	// When positive, a table is split into continuation tables so that every
	// part's headings fit unbroken at their columns' shares of the line. 0
	// splits by TableColumns alone.
	TableMeasure int
}

MarkdownOptions are the presentation choices of the Markdown backend. They are options of this backend, never document-model attributes.

type Stylesheet

type Stylesheet struct {
	// Content is stylesheet text to inline, keeping the document self-contained.
	Content string
	// Href is a stylesheet URL to link, for a site-hosted stylesheet.
	Href string
	// contains filtered or unexported fields
}

Stylesheet is one stylesheet a standalone document carries: Content is inlined, Href is linked. Exactly one of the two is set; InlineStylesheet states a sheet is inlined when its content is empty.

func InlineStylesheet

func InlineStylesheet(content string) Stylesheet

InlineStylesheet is a stylesheet inlined in the document, whose content may be empty: a file the run named is a stylesheet even when it declares nothing.

func LinkedStylesheet

func LinkedStylesheet(href string) Stylesheet

LinkedStylesheet is a stylesheet the document links rather than carries.

func (Stylesheet) Check

func (s Stylesheet) Check() error

Check rejects a stylesheet that is neither content nor URL, both at once, or whose content would close the <style> element it is inlined in.

Jump to

Keyboard shortcuts

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