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

Table of Contents

Other Languages

IncludeToken

Content wrapped in <includeonly> and </includeonly> when not transcluded, and content wrapped in <noinclude> and </noinclude> when transcluded.

✅ Available in the Mini and Browser versions.

Properties

name

✅ Expand

type: string
The name of the tag in lowercase, read-only.

// name
var {firstChild} = Parser.parse('<includeonly>a</includeonly>');
assert.equal(firstChild, '<includeonly>a</includeonly>');
assert.strictEqual(firstChild.name, 'includeonly');

closed

✅ Expand

type: boolean
Whether the tag is closed.

// closed
var {firstChild} = Parser.parse('<includeonly>a');
assert.equal(firstChild, '<includeonly>a');
assert(!firstChild.closed);
firstChild.closed = true;
assert.equal(firstChild, '<includeonly>a</includeonly>');

selfClosing

✅ Expand

type: boolean
Whether the tag is self-closing.

// selfClosing
var {firstChild} = Parser.parse('<includeonly>a</includeonly>');
assert.equal(firstChild, '<includeonly>a</includeonly>');
assert(!firstChild.selfClosing);
firstChild.selfClosing = true;
assert.equal(firstChild, '<includeonly/>');

innerText

✅ Expand

type: string
The text content of the tag.

// innerText
var {firstChild} = Parser.parse('<includeonly>a</includeonly>');
assert.equal(firstChild, '<includeonly>a</includeonly>');
assert.strictEqual(firstChild.innerText, 'a');
// innerText (main)
var {firstChild} = Parser.parse('<includeonly>a</includeonly>');
firstChild.innerText = 'b';
assert.equal(firstChild, '<includeonly>b</includeonly>');

hidden

Expand

type: true
IncludeToken is invisible, read-only.

// hidden (main)
var {firstChild} = Parser.parse('<includeonly>a</includeonly>');
assert.equal(firstChild, '<includeonly>a</includeonly>');
assert(firstChild.hidden);

Methods

lint

✅ Expand

version added: 1.3.2

returns: LintError[]
Report potential grammar errors.

// lint
var include = Parser.parse('<includeonly>a');
assert.equal(include, '<includeonly>a');
assert.deepEqual(include.lint(), [
	{
		rule: 'unclosed-comment',
		severity: 'error',
		message: 'unclosed <includeonly>',
		startLine: 0,
		startCol: 0,
		startIndex: 0,
		endLine: 0,
		endCol: 14,
		endIndex: 14,
		suggestions: [
			{
				desc: 'close',
				range: [14, 14],
				text: '</includeonly>',
			},
		],
	},
]);

cloneNode

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

removeAttr

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>');
⚠️ **GitHub.com Fallback** ⚠️