Documentation
¶
Overview ¶
Package document parses a markdown source file with YAML frontmatter into a Document value. The Document only carries the data parsed off disk; rendering lives in internal/render and theme resolution in internal/theme.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Default = Config{ MDoc: true, Theme: "", Title: "Untitled", Author: "Anonymous", Tags: []string{}, Page: Page{}, Data: map[string]any{}, }
Default is applied when a file has no frontmatter or its frontmatter does not opt in with `mdoc: true`.
Functions ¶
func FlattenGlobalIncludes ¶ added in v0.2.2
FlattenGlobalIncludes reads the file at path and returns its full text (kept verbatim, frontmatter and all) with every global `:::include` — a bare or scoped key such as `disclaimer` or `legal::contract` — recursively spliced inline, while local path includes (`./parts/intro.md`) are left as directives. The bundler uses it so global partials, which live outside the document tree and have no home in a portable archive, travel inside the bundled files. A document with no global includes comes back unchanged.
Types ¶
type Config ¶
type Config struct {
MDoc bool `yaml:"mdoc"`
Theme string `yaml:"theme"`
Title string `yaml:"title"`
Author string `yaml:"author"`
Tags []string `yaml:"tags"`
Page Page `yaml:"page"`
Data map[string]any `yaml:"data"`
References []Reference `yaml:"references"`
Numbering Numbering `yaml:"numbering"`
Labels map[string]string `yaml:"labels"`
}
Config is the YAML frontmatter shape.
type Document ¶
type Document struct {
Config Config
Body string
// Path is the absolute path to the source file.
Path string
// Dir is the absolute directory containing the source file. Relative
// references inside the document (images, includes) resolve from here.
Dir string
// Includes lists the absolute paths of files spliced into Body via
// `:::include`, in include order. Empty for documents that use no includes.
// The watcher (live preview) and the bundler read it so a change to any
// chapter triggers a reload and every chapter lands in the .mdoc archive.
Includes []string
}
Document is a parsed markdown source file.
type NumLevel ¶ added in v0.2.2
type NumLevel struct {
// Enabled toggles numbering for this level. nil inherits Numbering.Enabled;
// an explicit false leaves headings of this level unnumbered even when
// numbering is otherwise on (like applying the .unnumbered class to all of
// them).
Enabled *bool `yaml:"enabled"`
Template string `yaml:"template"`
Style string `yaml:"style"`
}
NumLevel tunes how one heading level is numbered. Template is a format string whose `{1}`..`{6}` placeholders render the counter at that level in the level's own Style; literal text (e.g. "§", separators) passes through verbatim. The single space that separates the number from the heading title is automatic, so trailing whitespace in a template is ignored. Examples: `template: "§{1}"` -> "§5", `template: "{1}.{2}"` with h2 `style: lower-alpha` -> "5.a". An empty Template falls back to the default for the level. Style is one of decimal, lower-roman, upper-roman, lower-alpha, upper-alpha (CSS list-style names); empty or unknown means decimal.
type Numbering ¶ added in v0.2.0
Numbering configures automatic heading numbering. It is off by default so ordinary documents don't get "1", "1.1" prefixes; thesis/report documents opt in with `numbering: {enabled: true}`. A `:::toc` works either way (entries just carry no number when numbering is off).
Levels optionally tunes individual heading levels by key ("h1".."h6"). When a level has no entry — or Levels is empty entirely — that level uses the built-in default (decimal, dot-joined: "1", "1.1", with appendix lettering), so existing documents render unchanged.
type Page ¶
Page mirrors the relevant parts of CSS @page. Both fields are passed through verbatim into the theme's @page rule, so anything CSS accepts (named sizes like "A4" / "Letter", explicit "210mm 297mm", "A4 landscape", the four-value margin shorthand, etc.) is valid. Themes provide the fallback when a field is empty.
type Reference ¶ added in v0.2.0
type Reference struct {
Key string `yaml:"key"`
ID string `yaml:"id"`
Author string `yaml:"author"`
Title string `yaml:"title"`
Year string `yaml:"year"`
Publisher string `yaml:"publisher"`
Edition string `yaml:"edition"`
ISBN string `yaml:"isbn"`
URL string `yaml:"url"`
Text string `yaml:"text"`
}
Reference is one bibliography entry. Cited from the body with `[@<key>]` and listed by a `:::bibliography` directive. If Text is set it is used verbatim (the raw escape-hatch); otherwise the structured fields are assembled by the renderer. Both `key` and `id` name the citation key.