theme

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package theme provides a registry of named themes plus loaders for custom CSS files. Resolve maps a name (built-in theme, "auto", a file path, or "") to a Theme struct containing the CSS, an optional vendored hljs sheet path, and a Mermaid theme identifier.

Binary bloat note

Importing pkg/theme pulls in the embedded vendor assets (highlight.js stylesheets, theme CSS) via the mdp assets package. The footprint is modest — a few hundred KB — but worth knowing for consumers that want to ship the smallest possible binary. Callers that only need the parser can import pkg/parser alone.

Usage

Resolve returns the Theme for any built-in name, "auto", or a CSS file path. The auto theme has empty CSS — the consumer is expected to skip server-side injection and let the browser's prefers-color-scheme media query drive appearance.

t, err := theme.Resolve("github-light")
if err != nil {
    log.Fatal(err)
}
fmt.Printf("hljs sheet: %s\n", t.HljsVendorCSS)
fmt.Printf("mermaid theme: %s\n", t.MermaidTheme)
fmt.Printf("is auto: %v\n", t.IsAuto())

Names returns all valid built-in theme names in sorted order, useful for CLI flag validation or theme-picker UIs.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Names

func Names() []string

Names returns all valid built-in theme names in sorted order. The themeAuto theme is not included since it's a special value.

Types

type Theme

type Theme struct {
	// CSS is the complete theme stylesheet (prose + hljs tokens + mermaid vars).
	// Empty for themeAuto — the base preview.css handles auto via media query.
	CSS string

	// HljsVendorCSS is the path to a vendored hljs sheet to inject via <link>.
	// Only set for github-light / github-dark. Empty for all other themes.
	HljsVendorCSS string

	// MermaidTheme is the string passed to mermaid.initialize().
	// "base" for named themes (uses CSS vars), "" for auto.
	MermaidTheme string
	// contains filtered or unexported fields
}

Theme holds everything the server needs to render a page with the correct styling.

func Resolve

func Resolve(name string) (Theme, error)

Resolve returns the Theme for the given name. name may be a built-in theme name, themeAuto, an empty string (treated as auto), or an absolute/relative path to a CSS file.

Example
package main

import (
	"fmt"

	"github.com/donaldgifford/mdp/pkg/theme"
)

func main() {
	t, err := theme.Resolve("github-light")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("mermaid=%q auto=%v hljs=%q\n", t.MermaidTheme, t.IsAuto(), t.HljsVendorCSS)
}
Output:
mermaid="base" auto=false hljs="/vendor/hljs/github.min.css"

func (Theme) IsAuto

func (t Theme) IsAuto() bool

IsAuto reports whether the theme is the auto theme — when true, server-side CSS injection is skipped and the browser's prefers-color-scheme media query drives appearance.

Jump to

Keyboard shortcuts

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