-
Notifications
You must be signed in to change notification settings - Fork 2
FileToken (EN)
Table of Contents
File。
✅ Available in the Mini and Browser versions.
✅ Expand
version added: 1.5.3
type: string
File extension, read-only.
// extension
var {firstChild} = Parser.parse('[[file:a.jpg]]');
assert.strictEqual(firstChild.extension, 'jpg');
Expand
type: string
File name,read-only.
// name (main)
var {firstChild} = Parser.parse('[[file:a]]');
assert.strictEqual(firstChild.name, 'File:A');
firstChild.firstChild.setText('file:b', 0);
assert.strictEqual(firstChild.name, 'File:B');
Expand
type: string | Title
File link.
// link (main)
var {firstChild, lastChild} = Parser.parse([[file:a]][[file:b|link=c]]');
assert.equal(firstChild, '[[file:a]]');
assert.equal(lastChild, '[[file:b|link=c]]');
assert.deepStrictEqual(firstChild.link, firstChild.normalizeTitle('file:a'));
assert.deepStrictEqual(lastChild.link, lastChild.normalizeTitle('c'));
firstChild.link = '//c';
assert.equal(firstChild, '[[file:a|link=//c]]');
Expand
type: {width: string, height: string}
Image size.
// size (main)
var {firstChild} = Parser.parse('[[file:a|x1px]]');
assert.deepStrictEqual(firstChild.size, {width: '', height: '1'});
firstChild.size = {width: '1', height: '1'};
assert.equal(firstChild, '[[file:a|1x1px]]');
Expand
type: number
Image width.
// width (main)
var {firstChild} = Parser.parse('[[file:a|1x1px]]');
assert.strictEqual(firstChild.width, '1');
firstChild.width = undefined;
assert.equal(firstChild, '[[file:a|x1px]]');
Expand
type: number
Image height.
// height (main)
var {firstChild} = Parser.parse('[[file:a|1x1px]]');
assert.strictEqual(firstChild.height, '1');
firstChild.height = undefined;
assert.equal(firstChild, '[[file:a|1px]]');
✅ Expand
returns: LintError[]
Report potential grammar errors.
// lint
var {firstChild} = Parser
.parse('[[file:a|frameless|framed|left|none|sub|top|b|c]]');
assert.deepStrictEqual(firstChild.lint(), [
{
rule: 'no-duplicate',
severity: 'error',
message: 'duplicated image caption parameter',
startLine: 0,
startCol: 44,
startIndex: 44,
endLine: 0,
endCol: 45,
endIndex: 45,
},
{
rule: 'no-duplicate',
severity: 'error',
message: 'duplicated image caption parameter',
startLine: 0,
startCol: 46,
startIndex: 46,
endLine: 0,
endCol: 47,
endIndex: 47,
},
{
rule: 'no-duplicate',
severity: 'error',
message: 'conflicting image frame parameter',
startLine: 0,
startCol: 9,
startIndex: 9,
endLine: 0,
endCol: 18,
endIndex: 18,
},
{
rule: 'no-duplicate',
severity: 'error',
message: 'conflicting image frame parameter',
startLine: 0,
startCol: 19,
startIndex: 19,
endLine: 0,
endCol: 25,
endIndex: 25,
},
{
rule: 'no-duplicate',
severity: 'error',
message: 'conflicting image horizontal-alignment parameter',
startLine: 0,
startCol: 26,
startIndex: 26,
endLine: 0,
endCol: 30,
endIndex: 30,
},
{
rule: 'no-duplicate',
severity: 'error',
message: 'conflicting image horizontal-alignment parameter',
startLine: 0,
startCol: 31,
startIndex: 31,
endLine: 0,
endCol: 35,
endIndex: 35,
},
{
rule: 'no-duplicate',
severity: 'error',
message: 'conflicting image vertical-alignment parameter',
startLine: 0,
startCol: 36,
startIndex: 36,
endLine: 0,
endCol: 39,
endIndex: 39,
},
{
rule: 'no-duplicate',
severity: 'error',
message: 'conflicting image vertical-alignment parameter',
startLine: 0,
startCol: 40,
startIndex: 40,
endLine: 0,
endCol: 43,
endIndex: 43,
},
]);
✅ Expand
returns: ImageParameterToken[]
Get all image parameter nodes.
// getAllArgs
var {firstChild} = Parser.parse('[[file:a|thumb|1px|link=b|alt=c|d]]');
assert.deepStrictEqual(firstChild.getAllArgs(), firstChild.childNodes.slice(1));
✅ Expand
param: string
parameter name
returns: ImageParameterToken[]
Get specified image parameter nodes.
// getArgs
var {firstChild} = Parser.parse('[[file:a|link=b|链接=c]]');
assert.deepStrictEqual(
firstChild.getArgs('link'),
firstChild.childNodes.slice(1),
);
✅ Expand
param: string
parameter name
returns: ImageParameterToken
Get effective node of the specified image parameter.
// getArg
var {firstChild} = Parser.parse('[[file:a|link=b|链接=c]]');
assert.strictEqual(firstChild.getArg('link'), firstChild.lastChild);
✅ Expand
param: string
parameter name
returns: string | true
Get effective value of the specified image parameter.
// getValue
var {firstChild} = Parser.parse('[[file:a|b|c]]');
assert.strictEqual(firstChild.getValue('caption'), 'c');
Expand
returns: ImageParameterToken[]
Get image frame parameter nodes.
// getFrameArgs (main)
var {firstChild} = Parser.parse('[[file:a|thumb]]');
assert.deepStrictEqual(firstChild.getFrameArgs(), [firstChild.lastChild]);
Expand
returns: ImageParameterToken[]
Get image horizontal alignment parameter nodes.
// getHorizAlignArgs (main)
var {firstChild} = Parser.parse('[[file:a|none]]');
assert.deepStrictEqual(firstChild.getHorizAlignArgs(), [firstChild.lastChild]);
Expand
returns: ImageParameterToken[]
Get image vertical alignment parameter nodes.
// getVertAlignArgs (main)
var {firstChild} = Parser.parse('[[file:a|top]]');
assert.deepStrictEqual(firstChild.getVertAlignArgs(), [firstChild.lastChild]);
Expand
returns: this
Deep clone the node.
// cloneNode (main)
var {firstChild} = Parser.parse('[[file:a]]');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);
Expand
param: string
target file name
Set target file.
// setTarget (main)
var {firstChild} = Parser.parse('[[file:a]]');
firstChild.setTarget('file:b');
assert.equal(firstChild, '[[file:b]]');
Expand
param: string
parameter name
returns: boolean
Whether the image has the specified parameter.
// hasArg (main)
var {firstChild} = Parser.parse('[[file:a|b]]');
assert(firstChild.hasArg('caption'));
Expand
param: string
parameter name
Remove the specified image parameter.
// removeArg (main)
var {firstChild} = Parser.parse('[[file:a|link=b]]');
firstChild.removeArg('link');
assert.equal(firstChild, '[[file:a]]');
Expand
returns(): Set<string>
Get image parameter names.
// getKeys (main)
var {firstChild} = Parser.parse('[[file:a|thumb|1px|link=b|alt=c|d]]');
assert.deepStrictEqual(
firstChild.getKeys(),
new Set(['thumbnail', 'width', 'link', 'alt', 'caption']),
);
Expand
param: string
parameter name
returns: (string | true)[]
Get specified image parameter values.
// getValues (main)
var {firstChild} = Parser.parse('[[file:a|b|c]]');
assert.deepStrictEqual(firstChild.getValues('caption'), ['b', 'c']);
Expand
param: string
parameter name
param: string | boolean
parameter value
Set the specified image parameter.
// setValue (main)
var {firstChild} = Parser.parse('[[file:a|thumb]]');
firstChild.setValue('thumbnail', false);
firstChild.setValue('width', '100');
firstChild.setValue('framed', true);
assert.equal(firstChild, '[[file:a|100px|framed]]');
对维基文本批量执行语法检查的命令行工具
用于维基文本的 ESLint 插件
A command-line tool that performs linting on Wikitext in bulk
ESLint plugin for Wikitext