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

Other Languages

Introduction

Category. This class inherits all the properties and methods of the LinkBaseToken class.

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

Properties

Inherited properties from LinkBaseToken

innerText

Expand

version added: 1.32.0

type: string
Link text.

// innerText (main)
var {firstChild} = Parser.parse("[[category:a_b|c]]");
assert.strictEqual(firstChild.innerText, "A b");

sortkey

🌐 Expand

type: string
Sort key. Read-only in the Browser version.

// sortkey (print)
var {
	firstChild,
	lastChild,
} = Parser.parse("[[category:a|<|]]][[category:b]]");
assert.strictEqual(firstChild.sortkey, "<|]");
assert.strictEqual(lastChild.sortkey, undefined);
// sortkey (main)
var {firstChild} = Parser.parse("[[category:a]]");
firstChild.sortkey = "b";
assert.equal(firstChild, "[[category:a|b]]");
firstChild.sortkey = undefined;
assert.equal(firstChild, "[[category:a]]");

type

✅ Expand

type: 'category'

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

Methods

Inherited methods from LinkBaseToken

json

🌐 Expand

Save the syntax tree as JSON.

// json (print)
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: " ",
				},
			],
		},
	],
});

setSortkey

Expand

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

⚠️ **GitHub.com Fallback** ⚠️