-
Notifications
You must be signed in to change notification settings - Fork 2
FileToken
目录
文件。
✅ 展开
加入的版本:1.5.3
type: string
文件扩展名,只读。
// extension
var {firstChild} = Parser.parse('[[file:a.jpg]]');
assert.strictEqual(firstChild.extension, 'jpg');
展开
type: string
文件页面名,只读。
// 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');
展开
type: string | Title
图片链接。
// 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]]');
展开
type: {width: string, height: string}
图片大小。
// 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]]');
展开
type: number
图片宽度。
// width (main)
var {firstChild} = Parser.parse('[[file:a|1x1px]]');
assert.strictEqual(firstChild.width, '1');
firstChild.width = undefined;
assert.equal(firstChild, '[[file:a|x1px]]');
展开
type: number
图片高度。
// height (main)
var {firstChild} = Parser.parse('[[file:a|1x1px]]');
assert.strictEqual(firstChild.height, '1');
firstChild.height = undefined;
assert.equal(firstChild, '[[file:a|1px]]');
✅ 展开
returns: LintError[]
报告潜在语法错误。
// 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,
suggestions: [
{
desc: 'remove',
range: [43, 45],
text: '',
},
],
},
{
rule: 'no-duplicate',
severity: 'error',
message: 'duplicated image caption parameter',
startLine: 0,
startCol: 46,
startIndex: 46,
endLine: 0,
endCol: 47,
endIndex: 47,
suggestions: [
{
desc: 'remove',
range: [45, 47],
text: '',
},
],
},
{
rule: 'no-duplicate',
severity: 'error',
message: 'conflicting image frame parameter',
startLine: 0,
startCol: 9,
startIndex: 9,
endLine: 0,
endCol: 18,
endIndex: 18,
suggestions: [
{
desc: 'remove',
range: [8, 18],
text: '',
},
],
},
{
rule: 'no-duplicate',
severity: 'error',
message: 'conflicting image frame parameter',
startLine: 0,
startCol: 19,
startIndex: 19,
endLine: 0,
endCol: 25,
endIndex: 25,
suggestions: [
{
desc: 'remove',
range: [18, 25],
text: '',
},
],
},
{
rule: 'no-duplicate',
severity: 'error',
message: 'conflicting image horizontal-alignment parameter',
startLine: 0,
startCol: 26,
startIndex: 26,
endLine: 0,
endCol: 30,
endIndex: 30,
suggestions: [
{
desc: 'remove',
range: [25, 30],
text: '',
},
],
},
{
rule: 'no-duplicate',
severity: 'error',
message: 'conflicting image horizontal-alignment parameter',
startLine: 0,
startCol: 31,
startIndex: 31,
endLine: 0,
endCol: 35,
endIndex: 35,
suggestions: [
{
desc: 'remove',
range: [30, 35],
text: '',
},
],
},
{
rule: 'no-duplicate',
severity: 'error',
message: 'conflicting image vertical-alignment parameter',
startLine: 0,
startCol: 36,
startIndex: 36,
endLine: 0,
endCol: 39,
endIndex: 39,
suggestions: [
{
desc: 'remove',
range: [35, 39],
text: '',
},
],
},
{
rule: 'no-duplicate',
severity: 'error',
message: 'conflicting image vertical-alignment parameter',
startLine: 0,
startCol: 40,
startIndex: 40,
endLine: 0,
endCol: 43,
endIndex: 43,
suggestions: [
{
desc: 'remove',
range: [39, 43],
text: '',
},
],
},
]);
✅ 展开
returns: ImageParameterToken[]
获取所有图片参数节点。
// getAllArgs
var {firstChild} = Parser.parse('[[file:a|thumb|1px|link=b|alt=c|d]]');
assert.deepStrictEqual(firstChild.getAllArgs(), firstChild.childNodes.slice(1));
✅ 展开
param: string
参数名
returns: ImageParameterToken[]
获取指定图片参数。
// getArgs
var {firstChild} = Parser.parse('[[file:a|link=b|链接=c]]');
assert.deepStrictEqual(
firstChild.getArgs('link'),
firstChild.childNodes.slice(1),
);
✅ 展开
param: string
参数名
returns: ImageParameterToken
获取生效的指定图片参数。
// getArg
var {firstChild} = Parser.parse('[[file:a|link=b|链接=c]]');
assert.strictEqual(firstChild.getArg('link'), firstChild.lastChild);
✅ 展开
param: string
参数名
returns: string | true
获取生效的指定图片参数值。
// getValue
var {firstChild} = Parser.parse('[[file:a|b|c]]');
assert.strictEqual(firstChild.getValue('caption'), 'c');
展开
returns: ImageParameterToken[]
获取图片框架属性参数节点。
// getFrameArgs (main)
var {firstChild} = Parser.parse('[[file:a|thumb]]');
assert.deepStrictEqual(firstChild.getFrameArgs(), [firstChild.lastChild]);
展开
returns: ImageParameterToken[]
获取图片水平对齐参数节点。
// getHorizAlignArgs (main)
var {firstChild} = Parser.parse('[[file:a|none]]');
assert.deepStrictEqual(firstChild.getHorizAlignArgs(), [firstChild.lastChild]);
展开
returns: ImageParameterToken[]
获取图片垂直对齐参数节点。
// getVertAlignArgs (main)
var {firstChild} = Parser.parse('[[file:a|top]]');
assert.deepStrictEqual(firstChild.getVertAlignArgs(), [firstChild.lastChild]);
展开
returns: this
深拷贝节点。
// cloneNode (main)
var {firstChild} = Parser.parse('[[file:a]]');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);
展开
param: string
文件目标
设置文件目标。
// setTarget (main)
var {firstChild} = Parser.parse('[[file:a]]');
firstChild.setTarget('file:b');
assert.equal(firstChild, '[[file:b]]');
展开
param: string
参数名
returns: boolean
是否具有指定图片参数。
// hasArg (main)
var {firstChild} = Parser.parse('[[file:a|b]]');
assert(firstChild.hasArg('caption'));
展开
param: string
参数名
移除指定图片参数。
// removeArg (main)
var {firstChild} = Parser.parse('[[file:a|link=b]]');
firstChild.removeArg('link');
assert.equal(firstChild, '[[file:a]]');
展开
returns(): Set<string>
获取图片参数名。
// 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']),
);
展开
param: string
参数名
returns: (string | true)[]
获取指定的图片参数值。
// getValues (main)
var {firstChild} = Parser.parse('[[file:a|b|c]]');
assert.deepStrictEqual(firstChild.getValues('caption'), ['b', 'c']);
展开
param: string
参数名
param: string | boolean
参数值
设置图片参数。
// 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