Documentation
¶
Overview ¶
Package render implements the build-time rendering pipeline: goldmark for Markdown (GFM, TOC, anchors, front matter, mermaid, optional glossary terms) and chroma for syntax highlighting. Relative links pointing at in-repo files are rewritten to /view/ paths at the AST level via an ASTTransformer — never by text replacement on rendered output. User HTML files are never parsed or modified (ADR-001).
Index ¶
- func GlossaryFrontMatterFields() []string
- func RelTo(fromURL, toURL string) string
- func StylesCSS(theme string) (string, error)
- func ValidGlossaryKey(key string) bool
- type CodeOptions
- type CodeResult
- type Glossary
- type GlossarySource
- type GlossaryStrictness
- type GlossaryTerm
- type GlossaryText
- type Kind
- type Markdown
- type MarkdownOptions
- type MarkdownResult
- type PageRef
- type TOCItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GlossaryFrontMatterFields ¶ added in v1.7.0
func GlossaryFrontMatterFields() []string
GlossaryFrontMatterFields returns the YAML keys honored by document front-matter glossary overlays.
func RelTo ¶
RelTo computes the relative URL from one site page URL to another. Both arguments are root-relative URLs like "view/docs/a.md/"; a trailing slash on toURL is preserved. Shared by the markdown link rewriter and the site assembly layer (spec 005).
func ValidGlossaryKey ¶ added in v1.7.0
ValidGlossaryKey reports whether key matches the glossary key pattern ^[a-z0-9]([a-z0-9-]*[a-z0-9])?$.
Types ¶
type CodeOptions ¶
CodeOptions controls code rendering without coupling render to internal/config.
type CodeResult ¶
CodeResult is a rendered code block plus metadata for templates.
func Code ¶
func Code(src []byte, filename string, opts CodeOptions) (CodeResult, error)
Code renders a source file as class-based Chroma HTML.
type Glossary ¶ added in v1.7.0
type Glossary map[string]GlossaryTerm
Glossary is the build-time public term library, indexed by normalized key. It is read-only at render time and safe for concurrent use.
type GlossarySource ¶ added in v1.7.0
type GlossarySource struct {
Label GlossaryText
URL string
}
type GlossaryStrictness ¶ added in v1.7.0
type GlossaryStrictness string
const ( GlossaryStrictOff GlossaryStrictness = "off" GlossaryStrictRefs GlossaryStrictness = "refs" GlossaryStrictComplete GlossaryStrictness = "complete" )
type GlossaryTerm ¶ added in v1.7.0
type GlossaryTerm struct {
Key string
Title GlossaryText
Alias GlossaryText
Summary GlossaryText
Page GlossaryText
Warning GlossaryText
Source *GlossarySource
// DefinedIn is the repo-relative path of the public glossary file.
// Private front-matter terms leave it empty.
DefinedIn string
}
func (GlossaryTerm) IsIncomplete ¶ added in v1.7.0
func (t GlossaryTerm) IsIncomplete() bool
IsIncomplete reports whether the term still lacks an explanation after front-matter overrides: both Summary and Page are empty. The result is meaningful for MarkdownResult.Terms, not for public-library entries.
type GlossaryText ¶ added in v1.7.0
GlossaryText is a glossary field in two forms. Text is the source with inline-code markers stripped, used for aria-label, search, and llms.txt. HTML is the escaped rendering with paired backticks turned into <code>.
func ParseGlossaryText ¶ added in v1.7.0
func ParseGlossaryText(raw string) GlossaryText
ParseGlossaryText converts a glossary field into Text and HTML forms.
type Markdown ¶
type Markdown struct {
// contains filtered or unexported fields
}
Markdown renders Markdown documents. It is safe to reuse concurrently.
func NewMarkdown ¶
func NewMarkdown() *Markdown
NewMarkdown assembles a Markdown renderer that caches goldmark pipelines by option combination.
func (*Markdown) Render ¶
func (m *Markdown) Render(src []byte, ref PageRef, opts MarkdownOptions) (MarkdownResult, error)
Render converts a Markdown document into HTML and extracts title, TOC, and front matter metadata.
type MarkdownOptions ¶
type MarkdownOptions struct {
TOC bool
TOCMinHeadings int
Anchors bool
Mermaid bool
FrontmatterTitle bool
// Glossary enables term annotations in the browsing-layer HTML.
Glossary bool
// GlossaryStrict controls undefined-key handling. An empty value equals
// GlossaryStrictRefs.
GlossaryStrict GlossaryStrictness
// Terms is the build-time public glossary, indexed by normalized key.
// It is read-only; Render never mutates it. A nil map is an empty library.
Terms Glossary
// GlossaryTermLabel is the aria-label format for .term links, with a
// single %s placeholder for the visible link text. Empty omits the
// attribute. Site fills this from theme.UIStrings so render stays
// language-agnostic.
GlossaryTermLabel string
}
MarkdownOptions controls Markdown rendering without coupling render to internal/config.
type MarkdownResult ¶
type MarkdownResult struct {
HTML template.HTML
Title string
TOC []TOCItem
HasMermaid bool
Meta map[string]any
// Terms holds the terms referenced on this page after front-matter
// overrides, in first-appearance order and de-duplicated by key.
Terms []GlossaryTerm
// Warnings holds recoverable issues from this page: front-matter
// glossary entries (invalid source URL, truncated fields) and
// undefined term references when GlossaryStrict is off. Public
// library problems are reported by site.LoadGlossary, not here.
Warnings []string
}
MarkdownResult is the rendered Markdown body plus metadata collected while parsing.
type PageRef ¶
type PageRef struct {
Path string
// Resolve returns "view" for files with a browsing page, "mirror" for
// files that should link to the raw mirror layer, or "" for unknown paths.
Resolve func(target string) string
}
PageRef identifies the current source file and resolves in-repository links.