ArgToken (EN) - bhsd-harry/wikiparser-node GitHub Wiki
Table of Contents
Template arguments wrapped in {{{}}}. This class inherits all the properties and methods of the Token class which are not repeated here.
✅ Available in the Mini and Browser versions.
🌐 Available in the Browser version.
🌐 Expand
type: string | false
Default value. Read-only in the Browser version.
// default (print)
var {firstChild} = Parser.parse("{{{a}}}");
assert.equal(firstChild, "{{{a}}}");
assert.strictEqual(firstChild.default, false);// default (main)
var {firstChild} = Parser.parse("{{{a}}}");
firstChild.default = "b";
assert.equal(firstChild, "{{{a|b}}}");✅ Expand
type: string
Name of the argument, read-only.
// name
var {firstChild} = Parser.parse("{{{a}}}");
assert.equal(firstChild, "{{{a}}}");
assert.strictEqual(firstChild.name, "a");// name (main)
var {firstChild} = Parser.parse("{{{a}}}"),
argName = firstChild.firstChild;
argName.replaceChildren("b");
assert.strictEqual(firstChild.name, "b");✅ Expand
returns: LintError[]
Report potential grammar errors.
// lint
var noinclude = Parser.parse("<ref>{{{a|b}}}</ref>").querySelector("arg"),
include = Parser.parse("{{{a|b|c}}}", true).firstChild;
assert.equal(noinclude, "{{{a|b}}}");
assert.deepStrictEqual(noinclude.lint(), [
{
rule: "no-arg",
severity: "warning",
message: "unexpected template argument",
startLine: 0,
startCol: 5,
startIndex: 5,
endLine: 0,
endCol: 14,
endIndex: 14,
suggestions: [
{
desc: "expand",
range: [5, 14],
text: "b",
},
],
},
{
rule: "arg-in-ext",
severity: "warning",
message: "template argument inside an extension tag",
startLine: 0,
startCol: 5,
startIndex: 5,
endLine: 0,
endCol: 14,
endIndex: 14,
},
]);
assert.equal(include, "{{{a|b|c}}}");
assert.deepStrictEqual(include.lint(), [
{
rule: "no-ignored",
severity: "error",
message: "invisible content inside triple braces",
startLine: 0,
startCol: 6,
startIndex: 6,
endLine: 0,
endCol: 8,
endIndex: 8,
suggestions: [
{
desc: "remove",
range: [6, 8],
text: "",
},
{
desc: "escape",
range: [6, 7],
text: "{{!}}",
},
],
},
]);🌐 Expand
Save the syntax tree as JSON.
// json (print)
var {lastChild} = Parser.parse(" {{{a}}}");
assert.deepStrictEqual(lastChild.json(), {
range: [1, 8],
type: "arg",
name: "a",
default: false,
childNodes: [
{
range: [4, 5],
type: "arg-name",
childNodes: [
{
range: [4, 5],
data: "a",
},
],
},
],
});Expand
returns: this
Deep clone the node.
// cloneNode (main)
var {firstChild} = Parser.parse("{{{a}}}");
assert.equal(firstChild, "{{{a}}}");
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);Expand
Remove redundant parts.
// removeRedundant (main)
var {firstChild} = Parser.parse("{{{a|b|c}}}");
assert.equal(firstChild, "{{{a|b|c}}}");
firstChild.removeRedundant();
assert.equal(firstChild, "{{{a|b}}}");Expand
param: string new argument name
Set the argument name.
// setName (main)
var {firstChild} = Parser.parse("{{{a}}}");
assert.equal(firstChild, "{{{a}}}");
firstChild.setName("b");
assert.equal(firstChild, "{{{b}}}");Expand
param: string
Set the default value.
// setDefault (main)
var {firstChild} = Parser.parse("{{{a}}}");
assert.equal(firstChild, "{{{a}}}");
firstChild.setDefault("b");
assert.equal(firstChild, "{{{a|b}}}");