moderator-toolbox-nxg-for-reddit / util/wiki/schemas/shared/tokens
util/wiki/schemas/shared/tokens¶
Functions¶
canonicalizeChoiceBlocks()¶
canonicalizeChoiceBlocks(
text):string
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:273
Rewrites every {choice} block in the text to its canonical form: each block
separated from surrounding content by exactly one blank line, options on
single - lines. Idempotent, so normalizing the NXG text and the
up-converted legacy mirror both land on the same string and config reconcile
sees no spurious difference. Text with no choice block is returned unchanged.
Parameters¶
text¶
string
The reason text to canonicalize.
Returns¶
string
decodeHtmlAngleBrackets()¶
decodeHtmlAngleBrackets(
text):string
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:57
Decodes HTML-entity-encoded angle brackets so <select> configs are treated
the same as configs that store literal <select> tags.
Handles any number of & prefixes (e.g. &amp;amp;lt;) so configs that
were entity-encoded multiple times by old toolbox or Reddit’s API round-trips
are recovered correctly.
Safe for surrounding markdown: SnuOwnd re-encodes any </> it sees, so the
display output is identical whether we pre-decode or not.
Parameters¶
text¶
string
Returns¶
string
htmlFieldsToTokens()¶
htmlFieldsToTokens(
text):string
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:435
Up-converts legacy (schema v1) reason text to token form: <input> and
<textarea> elements become inline tokens, <br> becomes a paragraph break,
and each <select> becomes an inline {choice} block (spliced in between
blank lines so the block marker lands on its own line; the caller’s
canonicalizeChoiceBlocks pass tidies the spacing).
Token-form text passes through unchanged, so this is safe (and idempotent) to apply to any reason text regardless of origin. The input must already have entity-encoded angle brackets decoded (see decodeHtmlAngleBrackets).
Parameters¶
text¶
string
The reason text to up-convert.
Returns¶
string
htmlSimpleFieldsToTokens()¶
htmlSimpleFieldsToTokens(
text):string
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:449
Up-converts only the inline legacy fields - <input>, <textarea>, and
<br> - leaving any <select> HTML untouched. Used for the removal message
header and footer, which display no interactive choice controls.
Parameters¶
text¶
string
The header/footer text to up-convert.
Returns¶
string
inlineSelectDefinitions()¶
inlineSelectDefinitions(
text,selects):string
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:333
Migrates the older v2 shape - a {select:name} reference resolving to a
separate definition - into the inline {choice} form. Each reference is
replaced by a block built from its definition: the prompt (if any) as a
markdown line above the marker, and the options as a list below it. A
reference whose definition is missing or empty is left untouched (it renders
literally). Idempotent: text with no {select:name} references is unchanged.
Parameters¶
text¶
string
The reason text containing {select:name} references.
selects¶
The reason’s legacy select definitions.
Returns¶
string
parseReasonSegments()¶
parseReasonSegments(
text):ReasonSegment[]
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:197
Splits reason text into literal-text and interactive-token segments, in
document order. Inline {input}/{textarea} tokens are matched anywhere; a
{choice} marker is recognized only on its own line and consumes the
consecutive markdown list lines immediately below it as its options (stopping
at the first blank or non-list line). A marker with no list line below it is
left as literal text, like any other unknown brace content.
Parameters¶
text¶
string
The reason text to parse.
Returns¶
pickSubstitutionTokens()¶
pickSubstitutionTokens(
tokens):SubstitutionTokenInfo[]
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:100
Picks a context-specific subset of substitutionTokens by token text, preserving the master list’s order. Editor UIs use this to offer only the tokens their context actually substitutes.
Parameters¶
tokens¶
string[]
Token texts including braces, e.g. '{author}'.
Returns¶
serializeToken()¶
serializeToken(
token):string
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:180
Serializes an interactive token back to its text form. A choice serializes to its block (marker + option list); inputs/textareas to their inline token.
Parameters¶
token¶
The token to serialize.
Returns¶
string
substituteTokenValues()¶
substituteTokenValues(
text,values):string
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:305
Replaces each interactive token in reason text with the corresponding user-entered value, in document order. Used when composing the final removal message; values map 1:1 to the rendered controls because the overlay renders them in the same order.
Parameters¶
text¶
string
The token-form reason text.
values¶
string[]
The entered values, in token order. Missing values become ‘’.
Returns¶
string
tokensToHtmlFields()¶
tokensToHtmlFields(
text):string
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:514
Down-converts token-form reason text to the legacy HTML form for the classic
(schema v1) wiki mirror: inline tokens become HTML form elements and each
{choice} block becomes a <select> element. Literal text - including
paragraph breaks, which 6.x handles fine as newlines - passes through
unchanged.
Parameters¶
text¶
string
The token-form reason text.
Returns¶
string
tokenToLegacyHtml()¶
tokenToLegacyHtml(
token):string
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:486
Serializes an interactive token to the legacy HTML element 6.x understands.
A choice’s id becomes the <select> id attribute; its options become
<option>s with markdown link characters backslash-escaped to survive 6.x’s
markdown pass. The choice’s prompt is plain text above the block, not part of
the token, so no label attribute is written.
Parameters¶
token¶
Returns¶
string
Interfaces¶
InteractiveToken¶
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:108
A parsed interactive token from removal reason text.
Properties¶
id?¶
optionalid?:string
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:116
Optional stable id, used to persist the entered/chosen value between
overlay opens and preserved as the HTML id attribute on the classic
mirror. Written as {input#someid: ...} for inputs/textareas and
{choice#someid} for choices.
kind¶
kind:
InteractiveTokenKind
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:109
options¶
options:
string[]
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:120
The option texts for choice tokens; empty for the other kinds.
placeholder¶
placeholder:
string
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:118
Placeholder text for input/textarea tokens; always ‘’ for choice.
LegacySelectDefinition¶
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:317
A legacy <select> definition the older v2 schema stored separately and
referenced from text as {select:name}. Only used by
inlineSelectDefinitions to migrate such configs to the inline form.
Properties¶
name¶
name:
string
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:318
options¶
options:
string[]
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:320
prompt?¶
optionalprompt?:string
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:319
SubstitutionTokenInfo¶
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:64
A substitution token ({author}, {url}, …) with a human-readable description for editor UIs.
Properties¶
description¶
description:
string
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:68
What the token expands to, phrased for a tooltip in the settings editor.
token¶
token:
string
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:66
The literal token text including braces, e.g. {author}.
Type Aliases¶
InteractiveTokenKind¶
InteractiveTokenKind =
"input"|"textarea"|"choice"
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:105
The kinds of interactive fill-in fields supported in reason text.
ReasonSegment¶
ReasonSegment = {
text:string;type:"text"; } | {token:InteractiveToken;type:"token"; }
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:124
A piece of reason text: either literal text or an interactive token.
Variables¶
substitutionTokens¶
constsubstitutionTokens:SubstitutionTokenInfo[]
Defined in: extension/data/util/wiki/schemas/shared/tokens.ts:77
The substitution tokens the removal overlay replaces with context data, in
the order editor UIs should offer them (common tokens first). Descriptions
match the values built in util/reddit/thingInfo.ts and consumed by the
overlay’s token source.