render

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 35 Imported by: 0

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

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

func RelTo(fromURL, toURL string) string

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 StylesCSS

func StylesCSS(theme string) (string, error)

StylesCSS returns the CSS rules for Chroma class-based HTML.

func ValidGlossaryKey added in v1.7.0

func ValidGlossaryKey(key string) bool

ValidGlossaryKey reports whether key matches the glossary key pattern ^[a-z0-9]([a-z0-9-]*[a-z0-9])?$.

Types

type CodeOptions

type CodeOptions struct {
	LineNumbers bool
	Theme       string
}

CodeOptions controls code rendering without coupling render to internal/config.

type CodeResult

type CodeResult struct {
	HTML  template.HTML
	Lang  string
	Lines int
}

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

type GlossaryText struct {
	Text string
	HTML template.HTML
}

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 Kind

type Kind int

Kind is the browser-layer rendering category for a source file.

const (
	KindMarkdown Kind = iota
	KindHTML
	KindCode
	KindImage
	KindBinary
)

func Classify

func Classify(path string, size int64, sniff []byte, maxFileSize int64) Kind

Classify returns the rendering category for a repo-relative file path. maxFileSize <= 0 disables the size limit. A nil or empty sniff is treated as an empty (text) file.

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.

type TOCItem

type TOCItem struct {
	Title    string
	Anchor   string
	Level    int
	Children []TOCItem
}

TOCItem is the template-friendly table of contents structure returned by Render.

Jump to

Keyboard shortcuts

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