-
Notifications
You must be signed in to change notification settings - Fork 2
ImageParameterToken (EN)
bhsd edited this page Jun 3, 2024
·
9 revisions
Table of Contents
Image parameter.
✅ Available in the Mini and Browser versions.
✅ Expand
type: string
Parameter name.
// name
var param = Parser.parse('[[file:a|b]]').querySelector('image-parameter');
assert.equal(param, 'b');
assert.strictEqual(param.name, 'caption');
✅ Expand
type: string | Title
Image link.
// link
var param = Parser.parse('[[file:a|link=//b]]')
.querySelector('image-parameter');
assert.equal(param, 'link=//b');
assert.strictEqual(param.link, '//b');
// link (main)
var param = Parser.parse('[[file:a|link=//b]]')
.querySelector('image-parameter');
param.link = 'c';
assert.equal(param, 'link=c');
Expand
type: string | true
See getValue
and setValue
methods.
// value (main)
var param = Parser.parse('[[file:a|thumb]]').querySelector('image-parameter');
assert.equal(param, 'thumb');
assert.strictEqual(param.value, true);
param.value = false;
assert.strictEqual(param.parentNode, undefined);
Expand
type: {width: string, height: string}
Image size.
// size (main)
var param = Parser.parse('[[file:a|1px]]').querySelector('image-parameter');
assert.equal(param, '1px');
assert.deepStrictEqual(param.size, {width: '1', height: ''});
param.size = {width: '', height: '2'};
assert.equal(param, 'x2px');
Expand
type: number
Image width.
// width (main)
var param = Parser.parse('[[file:a|1x1px]]').querySelector('image-parameter');
assert.equal(param, '1x1px');
assert.strictEqual(param.width, '1');
param.width = undefined;
assert.equal(param, 'x1px');
Expand
type: number
Image height.
// height (main)
var param = Parser.parse('[[file:a|1x1px]]').querySelector('image-parameter');
assert.equal(param, '1x1px');
assert.strictEqual(param.height, '1');
param.height = undefined;
assert.equal(param, '1px');
✅ Expand
returns: LintError[]
Report potential grammar errors.
// lint
var param = Parser.parse('[[file:a|link=%25]]')
.querySelector('image-parameter');
assert.equal(param, 'link=%25');
assert.deepStrictEqual(param.lint(), [
{
rule: 'url-encoding',
severity: 'error',
message: 'unnecessary URL encoding in an internal link',
startLine: 0,
startCol: 9,
startIndex: 9,
endLine: 0,
endCol: 17,
endIndex: 17,
},
]);
✅ Expand
returns: string | true
Get the parameter value.
// getValue
var [thumbnail, width] = Parser.parse('[[file:a|thumb|100px]]')
.querySelectorAll('image-parameter');
assert.equal(thumbnail, 'thumb');
assert.equal(width, '100px');
assert(thumbnail.getValue());
assert.strictEqual(width.getValue(), '100');
Expand
returns: this
Deep clone the node.
// cloneNode (main)
var param = Parser.parse('[[file:a|link=b]]').querySelector('image-parameter');
assert.equal(param, 'link=b');
assert.deepStrictEqual(param.cloneNode(), param);
Expand
param: string | true
parameter value
Set the parameter value.
// setValue (main)
var [thumbnail, width] = Parser.parse('[[file:a|thumb|100px]]')
.querySelectorAll('image-parameter');
assert.equal(thumbnail, 'thumb');
assert.equal(width, '100px');
thumbnail.setValue(false);
width.setValue('x100');
assert.strictEqual(thumbnail.parentNode, undefined);
assert.equal(width, 'x100px');
对维基文本批量执行语法检查的命令行工具
用于维基文本的 ESLint 插件
A command-line tool that performs linting on Wikitext in bulk
ESLint plugin for Wikitext