Skip to content

Examples (internal link) (EN)

Bhsd edited this page Apr 15, 2026 · 3 revisions

Other Languages

Setting the sort key of a category

Expand

You can set the sort key of a category in the content of a page. This example demonstrates the use of CategoryToken.

// Setting the sort key of a category (main)
// The content of a page containing `Category:Foo`
var content = `Foo

[[Category:Foo]]`,
	root = Parser.parse(content),
	category = root.querySelector('category#Category:Foo');
if (category) {
	category.setSortkey('*');
}
assert.equal(
	root,
	`Foo

[[Category:Foo|*]]`,
);

Removing blank alt attributes from images

Expand

You can removing blank alt attributes from images in the content of a page to improve accessibility. This example demonstrates the use of ImageParameterToken.

// Removing blank alt attributes from images (main)
// The content of a page containing images
var content = `[[File:Foo.jpg|alt=]]

<gallery>
Bar.jpg|alt=
</gallery>`,
	root = Parser.parse(content);
for (const parameter of root.querySelectorAll('image-parameter#alt')) {
	if (parameter.value === '') {
		parameter.remove();
	}
}
assert.equal(
	root,
	`[[File:Foo.jpg]]

<gallery>
Bar.jpg
</gallery>`,
);

Clone this wiki locally