IncludeToken (EN) - bhsd-harry/wikiparser-node GitHub Wiki
Content wrapped in <includeonly> and </includeonly> when not transcluded, and content wrapped in <noinclude> and </noinclude> when transcluded. This class inherits all the properties and methods of the TagPairToken class.
✅ Available in the Mini and Browser versions.
Inherited properties from TagPairToken
✅ Expand
type: string
The text content of the tag.
// innerText (main)
var {firstChild} = Parser.parse("<includeonly>a</includeonly>");
firstChild.innerText = "b";
assert.equal(firstChild, "<includeonly>b</includeonly>");
firstChild.innerText = undefined;
assert.equal(firstChild, "<includeonly/>");Inherited methods from TagPairToken
Expand
returns: this
Deep clone the node.
// cloneNode (main)
var {
childNodes: [closed, selfClosing, open],
} = Parser.parse("<includeonly>a</includeonly><includeonly/><includeonly>b");
assert.equal(closed, "<includeonly>a</includeonly>");
assert.equal(selfClosing, "<includeonly/>");
assert.equal(open, "<includeonly>b");
assert.deepStrictEqual(closed.cloneNode(), closed);
assert.deepStrictEqual(selfClosing.cloneNode(), selfClosing);
assert.deepStrictEqual(open.cloneNode(), open);✅ Expand
returns: LintError[]
Report potential grammar errors.
// lint
var {firstChild} = Parser.parse("<includeonly name=a></includeonly>");
assert.equal(firstChild, "<includeonly name=a></includeonly>");
assert.deepStrictEqual(firstChild.lint(), [
{
rule: "no-ignored",
severity: "warning",
message: "useless attribute",
startLine: 0,
startCol: 12,
startIndex: 12,
endLine: 0,
endCol: 19,
endIndex: 19,
suggestions: [
{
desc: "remove",
range: [12, 19],
text: "",
},
],
},
]);
({firstChild} = Parser.parse("<includeonly>a"));
assert.equal(firstChild, "<includeonly>a");
assert.deepStrictEqual(firstChild.lint(), [
{
rule: "unclosed-comment",
severity: "warning",
message: "unclosed <includeonly>",
startLine: 0,
startCol: 0,
startIndex: 0,
endLine: 0,
endCol: 14,
endIndex: 14,
suggestions: [
{
desc: "close",
range: [14, 14],
text: "</includeonly>",
},
],
},
]);Expand
Remove attributes. The attributes of the <includeonly> tag have no effect.
// removeAttr (main)
var {firstChild} = Parser.parse('<includeonly name="a">a</includeonly>');
assert.equal(firstChild, '<includeonly name="a">a</includeonly>');
firstChild.removeAttr();
assert.equal(firstChild, "<includeonly>a</includeonly>");Expand
param: string New text
Set the text content of the tag.
// setText (main)
var {firstChild} = Parser.parse("<includeonly>a</includeonly>");
assert.equal(firstChild, "<includeonly>a</includeonly>");
firstChild.setText("b");
assert.equal(firstChild, "<includeonly>b</includeonly>");