TagPairToken (EN) - bhsd-harry/wikiparser-node GitHub Wiki

Other Languages

Introduction

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.

Properties

closed

✅ 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);

innerText

✅ 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);

name

✅ 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');

selfClosing

✅ 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/>');

Methods

print

🌐 Expand

returns: string
Output in HTML format.

// print
var {firstChild} = Parser.parse('<pre/>');
assert.equal(
	firstChild.print(),
	'<span class="wpb-ext">&lt;pre/&gt;</span>',
);
({firstChild} = Parser.parse('<translate>a</translate>'));
assert.equal(
	firstChild.print(),
	`<span class="wpb-ext">&lt;translate&gt;<span class="wpb-ext-inner">a</span>&lt;/translate&gt;</span>`,
);
({firstChild} = Parser.parse('<includeonly>b'));
assert.equal(
	firstChild.print(),
	'<span class="wpb-include">&lt;includeonly&gt;b</span>',
);
⚠️ **GitHub.com Fallback** ⚠️