ListToken (EN) - bhsd-harry/wikiparser-node GitHub Wiki
Table of Contents
List at the start of the line. 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
version added: 1.16.5
type: number
Indentation.
// indent (print)
var {firstChild} = Parser.parse('::a');
assert.equal(firstChild, '::');
assert.strictEqual(firstChild.indent, 2);// indent (main)
var {firstChild} = Parser.parse('::a');
firstChild.indent = 1;
assert.equal(firstChild, ':');Expand
type: boolean
Whether it contains :, read-only.
// dd (main)
var {firstChild} = Parser.parse(':');
assert.ok(firstChild.dd);Expand
type: boolean
Whether it contains ;, read-only.
// dt (main)
var {firstChild} = Parser.parse(';');
assert.ok(firstChild.dt);Expand
type: boolean
Whether it contains *, read-only.
// ul (main)
var {firstChild} = Parser.parse('*');
assert.ok(firstChild.ul);Expand
type: boolean
Whether it contains #, read-only.
// ol (main)
var {firstChild} = Parser.parse('#');
assert.ok(firstChild.ol);✅ Expand
returns: LintError[]
Report potential grammar errors.
// lint
var list = Parser.parse(`Foo
#redirect [[Bar]]`).querySelector('list');
assert.equal(list, '#');
assert.deepStrictEqual(
list.lint(),
[
{
rule: 'syntax-like',
severity: 'error',
message: 'redirect-like syntax in a list item',
startLine: 1,
startCol: 0,
startIndex: 4,
endLine: 1,
endCol: 12,
endIndex: 16,
},
],
);🌐 Expand
Save the syntax tree as JSON.
// json (print)
var {lastChild} = Parser.parse('\n:');
assert.deepStrictEqual(lastChild.json(), {
range: [1, 2],
type: 'list',
indent: 1,
childNodes: [
{
range: [1, 2],
data: ':',
},
],
});Expand
returns: this
Deep clone the node.
// cloneNode (main)
var {firstChild} = Parser.parse(';');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);Expand
returns: Token
Get the range of the list.
// getRange (main)
var {firstChild} = Parser.parse(';a');
assert.equal(firstChild.getRange(), 'a');
({firstChild} = Parser.parse(';a:b'));
assert.equal(firstChild.getRange(), 'a');