-
Notifications
You must be signed in to change notification settings - Fork 3
Examples (template)
Expand
Given a template Template:Foo with an anonymouse parameter 1 which is deprecated in favor of a named parameter bar, you can replace the deprecated parameter with the new one in the content of a page. This example demonstrates the use of TranscludeToken.
// Replacing deprecated template parameters (main)
// The content of a page containing `Template:Foo`
var content = `{{Foo|Baz|Baz}}`,
root = Parser.parse(content);
for (const template of root.querySelectorAll('template#Template:Foo')) {
if (template.hasArg(1)) {
template.setValue('bar', template.getValue(1));
template.removeArg(1);
}
}
assert.equal(
root,
'{{Foo|2=Baz|bar=Baz}}',
);Expand
Given a template Template:Foo which is deprecated in favor of Template:Bar with the same parameters, you can replace the deprecated template with the new one in the content of a page. This example demonstrates the use of TranscludeToken.
// Replacing deprecated templates (main)
// The content of a page containing `Template:Foo`
var content = `{{Foo|Bar|Baz}}`,
root = Parser.parse(content);
for (const template of root.querySelectorAll('template#Template:Foo')) {
template.replaceTemplate('Bar');
}
assert.equal(
root,
'{{Bar|Bar|Baz}}',
);Expand
You can substitute a template in the content of a page if the template is not too complex. This example demonstrates the use of Token.prototype.expand.
// Substituting templates (main)
// The content of `Template:Foo`
Parser.templates.set('Template:Foo', '{{Bar|{{{a|}}}|{{{b|}}}|true}}');
// The content of `Template:Bar`
Parser.templates.set('Template:Bar', '{{#if:{{{3|}}}|{{{1|}}}\n{{{2|}}}\n}}');
// The content of a page containing `Template:Foo`
var content = `{{Foo|a=Bar|b=Baz}}`,
root = Parser.parse(content);
for (const template of root.querySelectorAll('template#Template:Foo')) {
template.replaceWith(template.expand());
}
assert.equal(
root,
`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