theme

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetThemeDescription

func GetThemeDescription(themeName string) string

GetThemeDescription returns the human-readable description for a theme.

Types

type ColorScheme

type ColorScheme struct {
	Text       string `yaml:"text"`
	Background string `yaml:"background"`
	Heading    string `yaml:"heading"`
	Link       string `yaml:"link"`
	CodeBg     string `yaml:"code_bg"`
	CodeText   string `yaml:"code_text"`
	Accent     string `yaml:"accent"`
	Border     string `yaml:"border"`
}

ColorScheme defines the color palette for a theme.

type MarginSettings

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

MarginSettings defines page margins in millimeters.

type Theme

type Theme struct {
	Name           string         `yaml:"name"`
	PageSize       string         `yaml:"page_size"` // e.g. A4, Letter
	FontFamily     string         `yaml:"font_family"`
	FontSize       int            `yaml:"font_size"` // in pt
	CodeTheme      string         `yaml:"code_theme"`
	LineHeight     float64        `yaml:"line_height"`
	Colors         ColorScheme    `yaml:"colors"`
	Margins        MarginSettings `yaml:"margins"`
	HeaderTemplate string         `yaml:"header_template"`
	FooterTemplate string         `yaml:"footer_template"`

	// FontSizeCSS overrides FontSize with a literal CSS length. book.yaml's
	// style.font_size accepts any CSS unit (px, em, rem, %), which the integer
	// point value above cannot represent, so the resolved config sets this
	// when the user configured a size. Empty means "use FontSize".
	FontSizeCSS string `yaml:"-"`
}

Theme defines the document theme styling.

func (*Theme) ApplyTypography added in v0.7.15

func (t *Theme) ApplyTypography(o TypographyOverride)

ApplyTypography overlays non-empty user typography onto the theme. Without it, style.font_family / font_size / line_height are parsed and validated but never reach any renderer.

func (*Theme) Clone

func (t *Theme) Clone() *Theme

Clone creates a deep copy of the theme.

func (*Theme) ResolvedFontSize added in v0.7.15

func (t *Theme) ResolvedFontSize() string

ResolvedFontSize returns the theme's body font size as a CSS length, taking a user override into account. Use it instead of formatting FontSize directly, so every backend agrees on the effective size.

func (*Theme) ScreenFontSizeCSS added in v0.8.3

func (t *Theme) ScreenFontSizeCSS() string

ScreenFontSizeCSS returns the body size the SITE should use. Theme sizes are print points — the right unit for the PDF, where 11pt is a book — but browsers map 11pt to 14.7px, two sizes below the 16px screen norm, so the same number that reads correctly on paper reads cramped on screen. The point value is rescaled anchored at 11pt→16px, preserving the themes' relative intent (minimal < technical < elegant). An explicit style.font_size override is returned verbatim: the author chose a unit on purpose.

func (*Theme) ToCSS

func (t *Theme) ToCSS() string

ToCSS converts theme settings to CSS code. Every var() usage carries a literal fallback derived from the theme values, so the styling survives engines without custom-property support.

func (*Theme) Validate

func (t *Theme) Validate() error

Validate checks theme fields for correctness.

type ThemeManager

type ThemeManager struct {
	// contains filtered or unexported fields
}

ThemeManager manages theme loading and retrieval.

func NewThemeManager

func NewThemeManager() *ThemeManager

NewThemeManager creates a new theme manager pre-loaded with built-in themes.

func (*ThemeManager) Get

func (tm *ThemeManager) Get(name string) (*Theme, error)

Get returns the theme with the given name.

func (*ThemeManager) List

func (tm *ThemeManager) List() []string

List returns the names of all available themes in sorted order.

func (*ThemeManager) LoadFromFile

func (tm *ThemeManager) LoadFromFile(path string) (*Theme, error)

LoadFromFile loads a theme from a YAML file.

type TypographyOverride added in v0.7.15

type TypographyOverride struct {
	FontFamily string
	FontSize   string
	LineHeight float64
}

TypographyOverride carries the typography settings from book.yaml's `style` block. They win over the theme's own values, so a user can retune a built-in theme without forking it.

Jump to

Keyboard shortcuts

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