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

Other Languages

Introduction

Header of a section.

✅ Available in the Mini and Browser versions.

Properties

level

✅ Expand

type: number
The level of the header, read-only.

// name
var {firstChild} = Parser.parse('==a==');
assert.equal(firstChild, '==a==');
assert.strictEqual(firstChild.level, 2);

innerText

Expand

type: string
The text content of the header.

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

Methods

lint

✅ Expand

returns: LintError[]
Report potential grammar errors.

// lint
var header = Parser.parse(`<p
=a''==
>`).querySelector('heading');
assert.equal(header, "=a''==");
assert.deepStrictEqual(header.lint(), [
	{
		rule: 'h1',
		severity: 'error',
		message: '<h1>',
		startLine: 1,
		startCol: 1,
		startIndex: 4,
		endLine: 1,
		endCol: 5,
		endIndex: 8,
	},
	{
		rule: 'unbalanced-header',
		severity: 'error',
		message: 'unbalanced "=" in a section header',
		startLine: 1,
		startCol: 1,
		startIndex: 4,
		endLine: 1,
		endCol: 5,
		endIndex: 8,
	},
	{
		rule: 'parsing-order',
		severity: 'error',
		message: 'section header in a HTML tag',
		startLine: 1,
		startCol: 0,
		startIndex: 3,
		endLine: 1,
		endCol: 6,
		endIndex: 9,
	},
	{
		rule: 'format-leakage',
		severity: 'error',
		message: 'unbalanced italic apostrophes in a section header',
		startLine: 1,
		startCol: 2,
		startIndex: 5,
		endLine: 1,
		endCol: 4,
		endIndex: 7,
	},
]);

cloneNode

Expand

returns: this
Deep clone the node.

// cloneNode
var {firstChild} = Parser.parse('==a==');
assert.equal(firstChild, '==a==');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);

setLevel

Expand

param: number Level of the header
Set the level of the header.

// setLevel
var {firstChild} = Parser.parse('==a==');
assert.equal(firstChild, '==a==');
firstChild.setLevel(3);
assert.equal(firstChild, '===a===');
⚠️ **GitHub.com Fallback** ⚠️