• 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:

    {restart link} {link to: "From the Top"} {link to: "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:
      • {restart link} calls render(null, {}, 'restart link')
      • {restart link, label: 'Try Again'} calls render(null, {label: 'Try Again}, "restart link, label: 'Try Again'")
      • {link to: 'Secret Room'} calls render('Secret Room', {}, "link to: 'Secret Room'")
      • {link to: 'Secret Room', hidden: true} calls render('Secret Room', {hidden: true}, "link to: 'Secret Room', hidden: true")

    If an insert can't be parsed successfully, it is left as-is.

    Parameters

    • source: string
    • inserts: Insert<Record<string, never>>[]

    Returns string

Generated using TypeDoc