Render inserts in a text string. Inserts are a mixture of variable
interpolation and template helpers marked off by curly braces.
The simplest insert is a variable name:
My favorite color is {color}. => My favorite color is red. (assuming that
color is a defined variable)
Inserts can also be syntax sugar for function calls:
{restartlink} {linkto: "From the Top"} {linkto: "From the Top", hidden: true}
Any number of extra arguments can be passed in key: value format. Keys must
be be able to be parsed as valid JavaScript object keys without being quoted,
and they may not be the same as the initial keyword (restart or link to
in the examples above). Inserts are set in the renderer as objects with two
keys:
match: a regular expression matching the inital invocation, e.g.
/^restart\s+link/. A match must include whitespace so it can never
conflict with a variable insert.
render: a function that takes a single argument, then props and raw
contents of the insert; and returns string output. Some examples:
Render inserts in a text string. Inserts are a mixture of variable interpolation and template helpers marked off by curly braces.
The simplest insert is a variable name:
My favorite color is {color}.
=>My favorite color is red.
(assuming thatcolor
is a defined variable)Inserts can also be syntax sugar for function calls:
Any number of extra arguments can be passed in
key: value
format. Keys must be be able to be parsed as valid JavaScript object keys without being quoted, and they may not be the same as the initial keyword (restart
orlink to
in the examples above). Inserts are set in the renderer as objects with two keys:match
: a regular expression matching the inital invocation, e.g./^restart\s+link/
. A match must include whitespace so it can never conflict with a variable insert.render
: a function that takes a single argument, then props and raw contents of the insert; and returns string output. Some examples:{restart link}
callsrender(null, {}, 'restart link')
{restart link, label: 'Try Again'}
callsrender(null, {label: 'Try Again}, "restart link, label: 'Try Again'")
{link to: 'Secret Room'}
callsrender('Secret Room', {}, "link to: 'Secret Room'")
{link to: 'Secret Room', hidden: true}
callsrender('Secret Room', {hidden: true}, "link to: 'Secret Room', hidden: true")
If an insert can't be parsed successfully, it is left as-is.