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

Other Languages

Introduction

Extended tags. This class includes the properties and methods of the AttributesToken class.

✅ Available in the Mini and Browser versions.

Properties

name

✅ Expand

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

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

selfClosing

✅ Expand

type: boolean
Whether the tag is self-closing.

// selfClosing
var {firstChild} = Parser.parse('<ref/>');
assert.equal(firstChild, '<ref/>');
assert(firstChild.selfClosing);
firstChild.selfClosing = false;
assert.equal(firstChild, '<ref></ref>');

innerText

✅ Expand

type: string
The text content of the tag, read-only.

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

Methods

lint

✅ Expand

returns: LintError[]
Report potential grammar errors.

// lint
var root = Parser.parse('<b title="a<ref>aa</ref>">aaa</b>'),
	ref = root.querySelector('ext#ref');
assert.equal(ref, '<ref>aa</ref>');
assert.deepStrictEqual(ref.lint(), [
	{
		rule: 'parsing-order',
		severity: 'error',
		message: 'extension tag in HTML tag attributes',
		startLine: 0,
		startCol: 11,
		startIndex: 11,
		endLine: 0,
		endCol: 24,
		endIndex: 24,
	},
]);

cloneNode

Expand

returns: this
Deep clone the node.

// cloneNode
var {firstChild, lastChild} = Parser.parse('<ref name="a">a</ref><ref name="a"/>'),
	closed = firstChild.cloneNode(),
	selfClosing = lastChild.cloneNode();
assert.equal(firstChild, '<ref name="a">a</ref>');
assert.equal(closed, '<ref name="a">a</ref>');
assert.equal(lastChild, '<ref name="a"/>');
assert.equal(selfClosing, '<ref name="a"/>');
assert.deepStrictEqual(closed, firstChild);
assert.deepStrictEqual(selfClosing, lastChild);
⚠️ **GitHub.com Fallback** ⚠️