shortcode

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 6 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.

func RedactHandler

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

RedactHandler implements the {{< redact >}} shortcode.

Parameters:

force="true"  - force full redaction
show="true"   - force no redaction
random="true" - random partial redaction
ratio="50"    - redaction ratio (0-100), default 50

Behavior:

  1. If force=true → redact
  2. If show=true → no redact
  3. Else, check page frontmatter "redact" field
  4. Else, check global redactFolders config (matches page directory)
  5. Apply full or random redaction based on mode

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