directive

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package directive implements site- and theme-authored generic directives: data-driven ::: blocks defined by a directives/<name>.yaml schema, an <name>.html html/template, and an optional <name>.css sidecar. The package is goldmark-agnostic; the parsing/rendering side lives in internal/content/markdown/extensions/genericdirective.

Index

Constants

View Source
const (
	KindContainer = "container"
	KindLeaf      = "leaf"
)

KindContainer directives have a markdown body rendered recursively; KindLeaf directives capture their body as raw text.

Variables

This section is empty.

Functions

func MergeCatalog

func MergeCatalog(base *engine.DirectiveCatalog, regs ...*Registry) *engine.DirectiveCatalog

MergeCatalog returns a new catalog combining the embedded built-in catalog with every registry's generic directives. Built-in entries are stamped Source "builtin"; generic directives land in one appended "custom" category. base is not mutated. Later registries win name conflicts among themselves; built-in name conflicts cannot occur because ValidateAgainstBuiltins removes them at load time.

func ValidName

func ValidName(name string) bool

ValidName reports whether name is a legal generic directive name.

Types

type Def

type Def struct {
	Name        string
	Kind        string // KindContainer | KindLeaf
	Label       string
	Description string
	Category    string
	Source      string // "site" | "theme" | "plugin:<slug>"
	Bracket     *engine.CatalogDirectiveBracket
	Fields      []engine.CatalogDirectiveField
	Template    *htmltemplate.Template
	CSS         []byte
	// contains filtered or unexported fields
}

Def is one loaded generic directive definition.

type Registry

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

Registry holds all loaded generic directive definitions. Load order gives overlay precedence: a directory loaded later overwrites same-named directives from earlier directories (plugins first, then theme, then site). The registry is immutable after loading and safe for concurrent read access.

func NewRegistry

func NewRegistry(funcMap htmltemplate.FuncMap) *Registry

NewRegistry creates an empty Registry. funcMap is applied to every directive template (the shortcode FuncMap: icon, i18n, URL helpers).

func (*Registry) CSS

func (r *Registry) CSS() string

CSS returns all directive CSS sidecars concatenated in name order, each prefixed with a header comment. Empty string when no directive ships CSS.

func (*Registry) CatalogEntries

func (r *Registry) CatalogEntries() []engine.CatalogDirective

CatalogEntries converts every definition into its catalog form, sorted by name. Kind maps to the catalog's "block"; every field placement is "attr".

func (*Registry) Empty

func (r *Registry) Empty() bool

Empty reports whether the registry has no definitions.

func (*Registry) Hash

func (r *Registry) Hash() string

Hash returns a sha256 hex digest over every definition's name, YAML, template, and CSS bytes, sorted by name. Folded into the markdown renderer's fingerprint so the page cache busts on any directive change. Empty string for an empty registry.

func (*Registry) LoadDir

func (r *Registry) LoadDir(dir, source string) []engine.ValidationWarning

LoadDir loads every <name>.yaml + <name>.html pair in dir, stamping source ("site" or "theme") on each definition. A missing dir is not an error. Invalid definitions are skipped with a warning; valid ones still load.

func (*Registry) Lookup

func (r *Registry) Lookup(name string) *Def

Lookup returns the definition for name, or nil.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns all registered directive names, sorted.

func (*Registry) ValidateAgainstBuiltins

func (r *Registry) ValidateAgainstBuiltins(cat *engine.DirectiveCatalog) []engine.ValidationWarning

ValidateAgainstBuiltins removes any directive whose name collides with a built-in catalog entry, returning one warning per removal. Built-ins always win: their bespoke parsers register ahead of the generic extension, so a colliding definition would silently never run.

type TemplateData

type TemplateData struct {
	Name  string            // directive name
	Label string            // bracket label or ""
	Attrs map[string]string // attrutil.Parse of the opening fence; missing keys read ""
	Body  htmltemplate.HTML // container: rendered children HTML; leaf: escaped raw text
}

TemplateData is the pipeline value every generic directive template executes against.

Jump to

Keyboard shortcuts

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