When Tea calls a macro’sDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/pompom454/tea/llms.txt
Use this file to discover all available pages before exploring further.
handler function, it sets this to a MacroContext instance that provides everything the handler needs: the parsed argument list, the DOM output element to write into, the inner content of container macros, and methods for rendering wiki markup, reporting errors, and navigating the ancestor macro chain.
MacroContext is not instantiated directly. You receive one as
this inside every handler function passed to Macro.add().Properties
this.args → Array<any>
An array of discrete arguments parsed from the macro’s argument string. TwineScript operators and expressions are evaluated before parsing.
this.args.full → string
The argument string after all TwineScript syntax elements have been converted to their native JavaScript equivalents.
this.args.raw → string
The raw, unprocessed argument string exactly as it appeared in the passage.
this.name → string
The canonical name of the macro (resolves alias chains to the original name).
this.output → HTMLElement
The DOM element into which the macro should render its output. Pass this to jQuery() or new Wikifier() to write content.
this.parent → Object | null
The MacroContext of the immediately enclosing macro, or null if this macro has no parent.
this.parser → Wikifier
The Wikifier parser instance that triggered this macro call.
this.payload → Array<Object> | null
For container macros (those with tags in their definition), this is an array of payload objects — one per tag block. For self-closing macros it is null.
Each payload object has:
The name of this tag block (the opening tag name, or a child tag name such as
"else").Discrete arguments for this tag block. Includes
args.full and args.raw sub-properties.The raw wiki-markup text between this tag and the next tag.
this.self → Object
The macro’s definition object — the same object passed to Macro.add(). Useful for reading custom properties you placed on the definition.
Methods
this.error(message) → boolean
Renders an error message prefixed with the macro’s name into the output element and returns false. Use a return this.error(...) pattern to abort handler execution on bad input.
The error message to display.
Always returns
false.this.wiki(sources…)
Parses one or more wiki-markup strings and appends the rendered result to this.output. Shorthand for creating a Wikifier against the output element.
One or more wiki-markup strings to render in sequence.
this.contextFilter(predicate) → Array<Object>
Returns an array of all ancestor MacroContext objects (walking up the parent chain) for which predicate returns true. Returns an empty array if none match.
A function that receives each ancestor context and returns a boolean.
Array of matching ancestor MacroContext objects.
this.contextFind(predicate) → Object | undefined
Returns the first ancestor MacroContext for which predicate returns true, or undefined if none match.
A function that receives each ancestor context and returns a boolean.
The first matching ancestor context, or
undefined.this.contextSome(predicate) → boolean
Returns true if any ancestor MacroContext satisfies the predicate.
A function that receives each ancestor context and returns a boolean.
true if at least one ancestor passes.this.shadowHandler(callback [, doneCallback [, startCallback]]) → Function
Returns a wrapper function that gives the callback access to variable shadows established by the <<capture>> macro. Use this whenever you need an asynchronous callback — such as a DOM event handler — to correctly read or write story/temporary variables that have been captured.
The main asynchronous function. Receives access to shadowed variables.
Optional cleanup function called after
callback returns. Does not receive shadow access.Optional initialization function called before
callback runs. Does not receive shadow access.A wrapped function suitable for use as an event handler or async callback.
Complete handler example
The following custom<<counted>> macro renders its contents and records how many times it has been visited: