-
Notifications
You must be signed in to change notification settings - Fork 2
FileToken
bhsd edited this page Nov 24, 2023
·
23 revisions
文件。这个类继承了 LinkToken 类。
- 链接目标。
var root = Parser.parse("[[file:a|link=[[talk:b]]]]"),
file = root.firstChild;
assert.deepStrictEqual(file.link, root.normalizeTitle('Talk:B'));
file.link = '//c';
assert.strictEqual(root.toString(), '[[file:a|link=//c]]');
size: {width: string, height: string}
- 图片尺寸。
var root = Parser.parse('[[file:a|x1px]]'),
file = root.firstChild;
assert.deepStrictEqual(file.size, {width: '', height: '1'});
- 图片宽度。
var root = Parser.parse('[[file:a|1x1px]]'),
file = root.firstChild;
assert.strictEqual(file.width, '1');
file.width = undefined;
assert.strictEqual(root.toString(), '[[file:a|x1px]]');
- 图片高度。
var root = Parser.parse('[[file:a|1x1px]]'),
file = root.firstChild;
assert.strictEqual(file.height, '1');
file.height = undefined;
assert.strictEqual(root.toString(), '[[file:a|1px]]');
getAllArgs(): ImageParameterToken[]
- 获取所有图片参数,类似 TranscludeToken.getAllArgs 方法。
var root = Parser.parse('[[file:a|thumb|1px|link=b|alt=c|d]]'),
file = root.firstChild;
assert.deepStrictEqual(file.getAllArgs(), file.children.slice(1));
getFrameArgs(): ImageParameterToken[]
- 获取图片框架参数,即
缩略图
、无框
、有框
等。每张图片只有第 1 个框架参数会生效。
var root = Parser.parse('[[file:a|thumb|1px|link=b|alt=c|d]]'),
file = root.firstChild;
assert.deepStrictEqual(file.getFrameArgs(), file.children.slice(1, 2));
getArgs(key: string): ImageParameterToken[]>
- 获取指定的图片参数,类似 TranscludeToken.getArgs 方法。
var root = Parser.parse('[[file:a|link=b|链接=c]]'), // 这里故意使用一个错误语法的例子,请勿模仿
file = root.firstChild;
assert.deepStrictEqual(file.getArgs('link'), file.children.slice(1));
- 是否带有指定的图片参数,类似 TranscludeToken.hasArg 方法。
var root = Parser.parse('[[file:a|b]]'),
file = root.firstChild;
assert(file.hasArg('caption') === true);
getArg(key: string): ImageParameterToken
- 获取最后一个指定的图片参数,类似 TranscludeToken.getArg 方法。
var root = Parser.parse('[[file:a|link=b|链接=c]]'), // 这里故意使用一个错误语法的例子,请勿模仿
file = root.firstChild;
assert.strictEqual(file.getArg('link'), file.lastChild);
- 移除指定的图片参数,类似 TranscludeToken.removeArg 方法。
var root = Parser.parse('[[file:a|link=b|链接=c]]'), // 这里故意使用一个错误语法的例子,请勿模仿
file = root.firstChild;
file.removeArg('link');
assert.strictEqual(root.toString(), '[[file:a]]');
- 获取所有图片参数名,类似 TranscludeToken.getKeys 方法,但允许重复。
var root = Parser.parse('[[file:a|thumb|1px|link=b|alt=c|d]]'),
file = root.firstChild;
assert.deepStrictEqual(file.getKeys(), ['thumbnail', 'width', 'link', 'alt', 'caption']);
getValue(key: string): string|true
- 获取指定的图片参数值,类似 TranscludeToken.getValue 方法。
var root = Parser.parse('[[file:a|thumb|100px]]'),
file = root.firstChild;
assert(file.getValue('thumbnail') === true);
assert.strictEqual(file.getValue('width'), '100');
setValue(key: string, value: string|boolean): void
- 修改或设置指定的图片参数,类似 TranscludeToken.setValue 方法。
var root = Parser.parse('[[file:a|thumb]]'),
file = root.firstChild;
file.setValue('thumbnail', false);
file.setValue('width', '100');
file.setValue('framed', true);
assert.strictEqual(root.toString(), '[[file:a|100px|framed]]');
对维基文本批量执行语法检查的命令行工具
用于维基文本的 VSCode 扩展
A command-line tool that performs linting on Wikitext in bulk
VSCode extension for Wikitext