-
Notifications
You must be signed in to change notification settings - Fork 3
Examples (tag) (EN)
Bhsd edited this page May 8, 2026
·
4 revisions
Expand
You can remove bolding from section headers in the content of a page. This example demonstrates the use of AstNode#remove.
// Removing bolding from section headers (main)
// The content of a page
import type {HtmlToken} from "wikiparser-node";
const content = `Foo
== <b>Bar</b> ==
=== <strong>Baz</strong> ===`,
root = Parser.parse(content),
boldings = root.querySelectorAll<HtmlToken>(
"heading-title > html:is(#b, #strong)",
);
for (const html of boldings) {
html.remove();
}
assert.equal(
root,
`Foo
== Bar ==
=== Baz ===`,
);Expand
You can replace the lang attribute of <syntaxhighlight> tags from moin to wikitext in the content of a page. This example demonstrates the use of ExtToken.
// Replacing the syntaxhighlight language (main)
// The content of a page containing `<syntaxhighlight>` tags
import type {ExtToken} from "wikiparser-node";
const content = `<syntaxhighlight lang="moin">
Foo
</syntaxhighlight>`,
root = Parser.parse(content),
exts = root.querySelectorAll<ExtToken>("ext#syntaxhighlight[lang=moin]");
for (const ext of exts) {
ext.setAttr("lang", "wikitext");
}
assert.equal(
root,
`<syntaxhighlight lang="wikitext">
Foo
</syntaxhighlight>`,
);Expand
You can easily fix invalid self-closing tags in the content of a page using HtmlToken#fix.
// Replacing the syntaxhighlight language (main)
// The content of a page containing invalid self-closing tags
import type {HtmlToken} from "wikiparser-node";
const content = "<div>Foo<div/>",
root = Parser.parse(content);
for (const html of root.querySelectorAll<HtmlToken>("html[selfClosing]")) {
try {
// May throw if it cannot be automatically fixed
html.fix();
} catch {}
}
assert.equal(
root,
"<div>Foo</div>",
);对维基文本批量执行语法检查的命令行工具
轻量级的维基模板解析器
维基文本语言服务器协议实现
用于维基文本的 VS Code 扩展
A command-line tool that performs linting on Wikitext in bulk
A lightweight Wikitext template parser
An implementation of the Language Server Protocol for Wikitext
VS Code extension for Wikitext