Documentation
¶
Overview ¶
Package docrender renders evaluated documents into backend-specific artifacts, consuming only the document IR — never plans, symbols, or ASTs.
Index ¶
- Constants
- func Captions(document *docir.Document) []string
- func DefaultStylesheet() string
- func DocumentFileName(fqn string) string
- func DocumentHTMLFileName(fqn string) string
- func HTML(document *docir.Document, opts HTMLOptions) (string, error)
- func Markdown(document *docir.Document, opts MarkdownOptions) (string, error)
- func StylesheetMarkup(sheets []Stylesheet) string
- func ThemePrintStylesheet(name string) (string, error)
- func ThemeStylesheet(name string) (string, error)
- func Themes() []string
- type Diagram
- type Error
- type ErrorKind
- type Formula
- type HTMLOptions
- type MarkdownOptions
- type Stylesheet
Constants ¶
const DefaultTheme = "default"
DefaultTheme names the default stylesheet on its own.
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.
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.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
ThemeStylesheet is the default stylesheet followed by the named theme's overrides in the same layer; empty or DefaultTheme is the default alone.
Types ¶
type Diagram ¶
Diagram is one graph-shaped diagram of a document: its declared name and its source in the requested diagram form.
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.
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 ¶
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.
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.