config

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentCSS

func ContentCSS(s string) string

ContentCSS converts a header/footer slot value to a CSS content value. Empty string produces `""`. Tokens {page} and {pages} become CSS counters.

func MergeFile

func MergeFile(cfg *Config, path string) error

MergeFile overlays the YAML file at path on top of cfg.

Types

type CodeConfig added in v0.0.7

type CodeConfig struct {
	Theme             string     `yaml:"theme"`
	Background        string     `yaml:"background"`
	Foreground        string     `yaml:"foreground"`
	FontFamily        string     `yaml:"font_family"`
	FontURL           string     `yaml:"font_url"`
	Faces             []FontFace `yaml:"faces"`
	FontSize          string     `yaml:"font_size"`
	LineHeight        float64    `yaml:"line_height"`
	LineNumbers       bool       `yaml:"line_numbers"`
	Wrap              bool       `yaml:"wrap"`
	KeepTogetherLines int        `yaml:"keep_together_lines"`
}

CodeConfig configures how fenced code blocks and inline code are rendered. Theme is a Chroma style name (see `templify --code-themes`); "none" or an empty value disables syntax highlighting and keeps the plain panel style. Background/Foreground override the colors the theme would otherwise pick.

type ColorsConfig

type ColorsConfig struct {
	Primary      string `yaml:"primary"`
	PrimaryLight string `yaml:"primary_light"`
	Background   string `yaml:"background"`
	Text         string `yaml:"text"`
	TextMuted    string `yaml:"text_muted"`
}

type Config

type Config struct {
	Page            PageConfig           `yaml:"page"`
	Font            FontConfig           `yaml:"font"`
	Headings        HeadingsConfig       `yaml:"headings"`
	Justify         bool                 `yaml:"justify"`
	ParagraphIndent string               `yaml:"paragraph_indent"`
	HeadingIndent   string               `yaml:"heading_indent"`
	HeadingNumbers  HeadingNumbersConfig `yaml:"heading_numbers"`
	TOC             TOCConfig            `yaml:"toc"`
	Header          HeaderFooterConfig   `yaml:"header"`
	Footer          HeaderFooterConfig   `yaml:"footer"`
	BlankPage       bool                 `yaml:"blank_page"`
	Colors          ColorsConfig         `yaml:"colors"`
	Code            CodeConfig           `yaml:"code"`
	Cover           CoverConfig          `yaml:"cover"`
	References      ReferencesConfig     `yaml:"references"`
	Custom          map[string]any       `yaml:"custom"`
	// contains filtered or unexported fields
}

func Default

func Default() *Config

Default returns a Config pre-filled with sensible defaults for page size, typography, colors, TOC, and footer page numbering.

func FromBundle

func FromBundle(data []byte) (*Config, error)

FromBundle builds a Config from the raw YAML of a bundle's default.yml. Falls back to Default() if data is nil.

func Load

func Load(path string) (*Config, error)

Load reads a YAML config file at path and overlays it on top of Default.

func (*Config) ApplyDocMeta

func (c *Config) ApplyDocMeta(meta map[string]any)

ApplyDocMeta overrides header/footer Left/Center/Right from the document's front matter. Front matter keys "header" and "footer" accept the same left/center/right sub-keys.

func (*Config) CustomBool

func (c *Config) CustomBool(path string, def bool) bool

CustomBool returns a bool value from Config.Custom at the given dot-separated path, falling back to def if the key is missing or the value is not a bool.

func (*Config) CustomString

func (c *Config) CustomString(path, def string) string

CustomString returns a string value from Config.Custom at the given dot-separated path, falling back to def if missing or not a string (e.g. "invoice.labels.client").

func (*Config) Dir added in v0.0.7

func (c *Config) Dir() string

Dir returns the directory of the config file, used to resolve relative paths.

func (*Config) FontFacesCSS added in v0.0.7

func (c *Config) FontFacesCSS() string

FontFacesCSS returns the inlined @font-face rules, or "" when no face is configured.

func (*Config) ResolvePath

func (c *Config) ResolvePath(p string) string

ResolvePath resolves a path relative to the config file's directory.

func (*Config) SetFontFacesCSS added in v0.0.7

func (c *Config) SetFontFacesCSS(css string)

SetFontFacesCSS stores the @font-face rules built from Font.Faces and Code.Faces. Reading and encoding the files happens before rendering, so the stylesheet generator stays free of I/O.

type CoverConfig

type CoverConfig struct {
	Enabled  bool   `yaml:"enabled"`
	Template string `yaml:"template"`
}

type FontConfig

type FontConfig struct {
	Family     string     `yaml:"family"`
	URL        string     `yaml:"url"`
	Faces      []FontFace `yaml:"faces"`
	Size       string     `yaml:"size"`
	LineHeight float64    `yaml:"line_height"`
}

FontConfig configures the body font. Faces takes precedence over URL: when it is set the linked stylesheet is dropped, since mixing the two would put the broken text layer back. Use `templify -fetch-fonts` to turn a URL into faces.

type FontFace added in v0.0.7

type FontFace struct {
	File         string `yaml:"file"`
	Weight       int    `yaml:"weight"`
	Style        string `yaml:"style"`
	UnicodeRange string `yaml:"unicode_range"`
}

FontFace is one self-hosted font file. Faces are inlined into the document's own stylesheet as data URIs. This matters for the PDF's text layer: fonts pulled in through a linked stylesheet are more likely to end up as a variable font, which Chromium's PDF export badly mis-positions; a static, self-hosted face avoids that specific cause (see docs/configuration.md's "Self-hosting fonts" section for the other causes of the same symptom, which self-hosting alone does not fix). File is resolved relative to the config file. Weight defaults to 400 and Style to normal. UnicodeRange is optional and passed through as-is.

type HeaderFooterConfig

type HeaderFooterConfig struct {
	Enabled    bool   `yaml:"enabled"`
	Background string `yaml:"background"`
	Left       string `yaml:"left"`
	Center     string `yaml:"center"`
	Right      string `yaml:"right"`
}

HeaderFooterConfig configures a header or footer band on every page. Left/Center/Right accept plain text or {page}/{pages} tokens.

type HeadingLevel

type HeadingLevel struct {
	Size            string `yaml:"size"`
	PageBreakBefore bool   `yaml:"page_break_before"`
}

type HeadingNumbersConfig

type HeadingNumbersConfig struct {
	Enabled bool     `yaml:"enabled"`
	Exclude []string `yaml:"exclude"`
}

type HeadingsConfig

type HeadingsConfig struct {
	H1 HeadingLevel `yaml:"h1"`
	H2 HeadingLevel `yaml:"h2"`
	H3 HeadingLevel `yaml:"h3"`
	H4 HeadingLevel `yaml:"h4"`
	H5 HeadingLevel `yaml:"h5"`
	H6 HeadingLevel `yaml:"h6"`
}

type MarginsConfig

type MarginsConfig struct {
	Top    string `yaml:"top"`
	Right  string `yaml:"right"`
	Bottom string `yaml:"bottom"`
	Left   string `yaml:"left"`
}

type PageConfig

type PageConfig struct {
	Size    string        `yaml:"size"`
	Margins MarginsConfig `yaml:"margins"`
}

type ReferencesConfig

type ReferencesConfig struct {
	Bibliography string `yaml:"bibliography"` // h2 heading text of the bibliography section
	Sitography   string `yaml:"sitography"`   // h2 heading text of the sitography section
	Figures      string `yaml:"figures"`      // h2 heading text for the auto-generated table of figures
}

type TOCConfig

type TOCConfig struct {
	Enabled  bool     `yaml:"enabled"`
	MaxDepth int      `yaml:"max_depth"`
	Exclude  []string `yaml:"exclude"`
	PreTOC   []string `yaml:"pre_toc"` // sections extracted from body and placed before the TOC
}

Jump to

Keyboard shortcuts

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