shortcode

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseParams

func ParseParams(raw string) map[string]string

ParseParams extracts key=value pairs from a raw attribute string.

Types

type Processor

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

Processor applies shortcode substitution to raw markdown before Goldmark runs.

func NewProcessor

func NewProcessor(registry *Registry) *Processor

NewProcessor creates a Processor backed by the given registry.

func (*Processor) Process

func (p *Processor) Process(
	markdown string,
	page *engine.Page,
	site *engine.SiteContext,
	mdRenderer engine.MarkdownRenderer,
) (string, []engine.ValidationWarning)

Process applies all shortcode substitutions to the markdown source. mdRenderer is passed per-call for goroutine safety (caller passes its pool-borrowed renderer).

type Registry

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

Registry manages shortcode templates with three-layer override support. Shortcodes are user-defined content components invoked from markdown via {{< name >}} syntax. The registry is immutable after construction and safe for concurrent read access.

func NewRegistry

func NewRegistry(embeddedFS fs.FS, funcMap htmltemplate.FuncMap) (*Registry, error)

NewRegistry creates a Registry and loads built-in shortcodes from the embedded FS.

func (*Registry) Has

func (r *Registry) Has(name string) bool

Has returns true if the registry contains a shortcode with the given name.

func (*Registry) LoadOverridesFromDir

func (r *Registry) LoadOverridesFromDir(dir string) error

LoadOverridesFromDir loads shortcode overrides from a filesystem directory. Each .html file overrides the shortcode named after the file (without extension).

func (*Registry) Names

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

Names returns all registered shortcode names.

func (*Registry) Register

func (r *Registry) Register(name string, content []byte) error

Register parses raw template bytes and registers the result under name.

func (*Registry) Resolve

func (r *Registry) Resolve(name string) *htmltemplate.Template

Resolve returns the template for a named shortcode, or nil if not registered.

func (*Registry) TemplateHash

func (r *Registry) TemplateHash() string

TemplateHash returns a sha256 hex digest over all registered template sources, sorted by name. Used for cache invalidation in dev mode.

type ShortcodeContext

type ShortcodeContext struct {
	Params map[string]string
	Inner  htmltemplate.HTML
	Page   *engine.Page
	Site   *engine.SiteContext
}

ShortcodeContext is the data object passed to every shortcode template.

Jump to

Keyboard shortcuts

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