interp

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package interp evaluates Go text/template interpolations in a slide deck's Markdown before the Markdown itself is parsed.

The whole body is executed as one template, so a template can generate slides: a {{range}} that emits "---" separators is a deck generator. The page number and the page total are only known once the deck has been split and paginated, so the page and total functions emit sentinels and Resolve replaces them afterwards. Every template is therefore evaluated exactly once, and a value coming from data is never re-parsed as one.

Code is left alone by default: fenced code blocks and inline code spans are set aside before execution and restored verbatim afterwards, so a slide about Go templates can show {{ .Name }} without escaping it.

Index

Constants

This section is empty.

Variables

View Source
var (
	PageSentinel  = sentinelOpen + "page" + sentinelClose
	TotalSentinel = sentinelOpen + "total" + sentinelClose
)

PageSentinel and TotalSentinel are what the page and total template functions produce.

Functions

func Expand

func Expand(src string, opts Options) (string, error)

Expand executes src as a template.

func Funcs

func Funcs(opts Options) template.FuncMap

Funcs is the function map available to templates.

func HasSentinel

func HasSentinel(s string) bool

HasSentinel reports whether s still holds an unresolved sentinel.

func Resolve

func Resolve(s string, page, total int) string

Resolve replaces the page and total sentinels.

Types

type Options

type Options struct {
	// Data is the template's dot.
	Data map[string]any
	// Delims overrides the action delimiters; both empty means "{{" "}}".
	Delims [2]string
	// Code, when true, interpolates inside code blocks and spans too.
	Code bool
	// BaseDir resolves the include function's relative paths.
	BaseDir string
	// Name names the template in error messages.
	Name string
	// Now is the clock behind the now function; nil means time.Now.
	Now func() time.Time
}

Options configures one evaluation.

Jump to

Keyboard shortcuts

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