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

Other Languages

Introduction

Category. This class inherits all the properties and methods of the LinkBaseToken class which are not repeated here.

✅ Available in the Mini and Browser versions.
🌐 Available in the Browser version.

Properties

type

✅ Expand

type: 'category'

// type
var {firstChild} = Parser.parse('[[category:a]]');
assert.strictEqual(firstChild.type, 'category');

sortkey

🌐 Expand

type: string
Sort key.

// sortkey (print)
var {firstChild} = Parser.parse('[[category:a|<|]]]');
assert.strictEqual(firstChild.sortkey, '<|]');
// sortkey (main)
var {firstChild} = Parser.parse('[[category:a|&lt;&#124;&#x5d;]]');
firstChild.sortkey = 'b';
assert.equal(firstChild, '[[category:a|b]]');

Methods

json

🌐 Expand

Save the syntax tree as JSON.

// json
var {lastChild} = Parser.parse(' [[category:a| ]]');
assert.deepStrictEqual(lastChild.json(), {
	range: [1, 17],
	type: 'category',
	name: 'Category:A',
	sortkey: ' ',
	childNodes: [
		{
			range: [3, 13],
			type: 'link-target',
			childNodes: [
				{
					range: [3, 13],
					data: 'category:a',
				},
			],
		},
		{
			range: [14, 15],
			type: 'link-text',
			childNodes: [
				{
					range: [14, 15],
					data: ' ',
				},
			],
		},
	],
});

cloneNode

Expand

returns: this
Deep clone the node.

// cloneNode (main)
var {firstChild} = Parser.parse('[[category:a#b|c]]');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);

setSortkey

Expand

param: string sort key
Set the sort key. Alias of LinkBaseToken.prototype.setLinkText.

toHtml

Expand

version added: 1.10.0

returns: string
Convert to HTML.

// toHtml (main)
var {firstChild} = Parser.parse('[[category:a]]');
assert.strictEqual(firstChild.toHtml(), '');
⚠️ **GitHub.com Fallback** ⚠️