-
Notifications
You must be signed in to change notification settings - Fork 3
Examples (list)
Bhsd edited this page Apr 15, 2026
·
6 revisions
Expand
You can increase the indentation of a definition list in the content of a page. This example demonstrates the use of ListToken.
// Increasing indentation of list items (main)
// The content of a page containing a definition list
var content = `: Foo
:: Bar`,
root = Parser.parse(content);
for (const list of root.querySelectorAll('list')) {
if (!list.ul && !list.ol && !list.dt) {
list.indent++;
}
}
assert.equal(
root,
`::Foo
:::Bar`,
);Expand
You can convert definition terms to section headers in the content of a page. This example demonstrates the use of Token.prototype.buildLists and ListToken.
// Converting definition terms to section headers (main)
// The content of a page containing definition terms
var content = `== Foo ==
; Bar
Baz`,
root = Parser.parse(content);
root.buildLists();
var sections = root.sections();
for (const dt of root.querySelectorAll('root > list')) {
const {nextSibling} = dt;
if (
dt.ul || dt.ol || dt.dl
|| nextSibling?.type !== 'list-range'
|| !nextSibling.text().trim()
// Not a lonely definition term
|| nextSibling.nextSibling?.type === 'dd'
|| nextSibling.nextSibling?.text() === '\n'
&& nextSibling.nextSibling.nextSibling?.type === 'list'
) {
continue;
}
const level = sections.findLast(
({childNodes}) => childNodes.includes(dt),
)?.querySelector('heading')?.level;
if (level) {
const title = nextSibling.text().trim(),
equals = '='.repeat(level + 1);
nextSibling.remove();
dt.replaceWith(`${equals} ${title} ${equals}`);
}
}
assert.equal(
root,
`== Foo ==
=== Bar ===
Baz`,
);对维基文本批量执行语法检查的命令行工具
轻量级的维基模板解析器
维基文本语言服务器协议实现
用于维基文本的 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