docrender

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 13 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 DefaultTheme = "default"

DefaultTheme names the default stylesheet on its own.

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 Captions

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

Captions lists the document's table, diagram and formula 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.

func DefaultStylesheet

func DefaultStylesheet() string

func DocumentFileName

func DocumentFileName(fqn string) string

DocumentFileName derives the deterministic Markdown file name of a rendered document from its fully-qualified name, using the same escaping as anchors so distinct documents never collide.

func DocumentHTMLFileName

func DocumentHTMLFileName(fqn string) string

DocumentHTMLFileName derives the deterministic HTML file name of a rendered document from its fully-qualified name, escaped as anchors are so distinct documents never collide.

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 (table-kind 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 Diagram

type Diagram struct {
	Name   string
	Source string
}

Diagram is one graph-shaped diagram of a document: its declared name and its source in the requested diagram form.

func Diagrams

func Diagrams(document *docir.Document, form view.Form, unplaced view.Unplaced) ([]Diagram, error)

Diagrams lists the document's graph-shaped diagrams in document order, each with the source the backends write for it in form (Mermaid when empty) with unplaced nodes placed as unplaced says. A table-kind view is a table, not a diagram, and is left out.

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"
)

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

	// 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,
	// Mermaid when empty; a table-kind view is a table whichever it is.
	DiagramForm view.Form

	// Unplaced is where a DOT diagram some Layout positions puts the nodes
	// none does: left undrawn when empty, or in a strip below the drawing.
	Unplaced view.Unplaced

	// 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

	// 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
}

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

type MarkdownOptions

type MarkdownOptions struct {
	// DiagramForm is the source every graph-shaped diagram is written as,
	// Mermaid when empty; a table-kind view is a pipe table whichever it is.
	DiagramForm view.Form

	// Unplaced is where a DOT diagram some Layout positions puts the nodes
	// none does: left undrawn when empty, or in a strip below the drawing.
	Unplaced view.Unplaced
}

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