render

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package render implements the build-time rendering pipeline: goldmark for Markdown (GFM, TOC, anchors, front matter, mermaid) 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 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.

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 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 the reusable Markdown rendering pipelines.

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
}

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
}

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