shortcode

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package shortcode provides Hugo-compatible shortcode registration and expansion.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AudioHandler

func AudioHandler(ctx *Context) (string, error)

AudioHandler implements the {{< audio src="..." title="..." >}} shortcode. Mirrors themes/zozo/layouts/shortcodes/audio.html.

func ImgHandler

func ImgHandler(ctx *Context) (string, error)

ImgHandler implements the {{< img src="..." title="..." >}} shortcode. Mirrors themes/zozo/layouts/shortcodes/img.html.

Types

type Context

type Context struct {
	Params map[string]string
	Inner  string // content between {{< x >}}...{{< /x >}}
	Args   []string
	Page   *content.Page
	Site   *content.Site
}

Context is what a shortcode handler receives.

type Handler

type Handler func(ctx *Context) (string, error)

Handler is a function that renders a shortcode.

type Registry

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

Registry holds all registered shortcode handlers.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new shortcode registry with built-in shortcodes registered.

func (*Registry) Expand

func (r *Registry) Expand(body string, page *content.Page, site *content.Site) (string, error)

Expand processes all shortcodes in the given markdown body. It handles both inline (self-closing) and block (with inner content) forms. Unknown shortcodes are left in place untouched.

func (*Registry) Has

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

Has reports whether a shortcode is registered.

func (*Registry) Register

func (r *Registry) Register(name string, handler Handler)

Register adds or replaces a shortcode handler.

Jump to

Keyboard shortcuts

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