TagPairToken (EN) - bhsd-harry/wikiparser-node GitHub Wiki
The parent class of IncludeToken, TranslateToken and ExtToken. 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: boolean
Whether the tag pair is properly closed.
// closed
var {firstChild} = Parser.parse('<includeonly> a');
assert.equal(firstChild, '<includeonly> a');
assert.ok(!firstChild.closed);
firstChild.closed = true;
assert.equal(firstChild, '<includeonly> a</includeonly>');
({firstChild} = Parser.parse('<pre/>'));
assert.equal(firstChild, '<pre/>');
assert.ok(firstChild.closed);
✅ Expand
type: string | undefined
If the tag is not self-closing, this property contains the text content inside the tag pair. Read-only.
// innerText
var {firstChild} = Parser.parse('<translate> a </translate>');
assert.equal(firstChild, '<translate> a </translate>');
assert.strictEqual(firstChild.innerText, ' a ');
({firstChild} = Parser.parse('<includeonly> b'));
assert.equal(firstChild, '<includeonly> b');
assert.strictEqual(firstChild.innerText, ' b');
({firstChild} = Parser.parse('<pre/>'));
assert.equal(firstChild, '<pre/>');
assert.strictEqual(firstChild.innerText, undefined);
✅ Expand
type: string
Tag name in lowercase.
// name
var {firstChild} = Parser.parse('<PRE/>');
assert.equal(firstChild, '<PRE/>');
assert.strictEqual(firstChild.name, 'pre');
({firstChild} = Parser.parse('<translate></translate>'));
assert.equal(firstChild, '<translate></translate>');
assert.strictEqual(firstChild.name, 'translate');
({firstChild} = Parser.parse('<includeonly>'));
assert.equal(firstChild, '<includeonly>');
assert.strictEqual(firstChild.name, 'includeonly');
✅ Expand
type: boolean
Whether the tag is self-closing.
// selfClosing
var {firstChild} = Parser.parse('<nowiki>a</nowiki>');
assert.equal(firstChild, '<nowiki>a</nowiki>');
assert.ok(!firstChild.selfClosing);
firstChild.selfClosing = true;
assert.equal(firstChild, '<nowiki/>');
🌐 Expand
returns: string
Output in HTML format.
// print
var {firstChild} = Parser.parse('<pre/>');
assert.equal(
firstChild.print(),
'<span class="wpb-ext"><pre/></span>',
);
({firstChild} = Parser.parse('<translate>a</translate>'));
assert.equal(
firstChild.print(),
`<span class="wpb-ext"><translate><span class="wpb-ext-inner">a</span></translate></span>`,
);
({firstChild} = Parser.parse('<includeonly>b'));
assert.equal(
firstChild.print(),
'<span class="wpb-include"><includeonly>b</span>',
);