FileToken - bhsd-harry/wikiparser-node GitHub Wiki

目录

Other Languages

简介

文件。

✅ 在 MiniBrowser 版本中可用。

Properties

extension

✅ 展开

加入的版本:1.5.3

type: string
文件扩展名,只读。

// extension
var {firstChild} = Parser.parse('[[file:a.jpg]]');
assert.strictEqual(firstChild.extension, 'jpg');

name

展开

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');

link

展开

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]]');

size

展开

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]]');

width

展开

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]]');

height

展开

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]]');

Methods

lint

✅ 展开

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,
	},
	{
		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,
	},
]);

getAllArgs

✅ 展开

returns: ImageParameterToken[]
获取所有图片参数节点。

// getAllArgs
var {firstChild} = Parser.parse('[[file:a|thumb|1px|link=b|alt=c|d]]');
assert.deepStrictEqual(firstChild.getAllArgs(), firstChild.childNodes.slice(1));

getArgs

✅ 展开

param: string 参数名
returns: ImageParameterToken[]
获取指定图片参数。

// getArgs
var {firstChild} = Parser.parse('[[file:a|link=b|链接=c]]');
assert.deepStrictEqual(
	firstChild.getArgs('link'),
	firstChild.childNodes.slice(1),
);

getArg

✅ 展开

param: string 参数名
returns: ImageParameterToken
获取生效的指定图片参数。

// getArg
var {firstChild} = Parser.parse('[[file:a|link=b|链接=c]]');
assert.strictEqual(firstChild.getArg('link'), firstChild.lastChild);

getValue

✅ 展开

param: string 参数名
returns: string | true
获取生效的指定图片参数值。

// getValue
var {firstChild} = Parser.parse('[[file:a|b|c]]');
assert.strictEqual(firstChild.getValue('caption'), 'c');

getFrameArgs

展开

returns: ImageParameterToken[]
获取图片框架属性参数节点。

// getFrameArgs (main)
var {firstChild} = Parser.parse('[[file:a|thumb]]');
assert.deepStrictEqual(firstChild.getFrameArgs(), [firstChild.lastChild]);

getHorizAlignArgs

展开

returns: ImageParameterToken[]
获取图片水平对齐参数节点。

// getHorizAlignArgs (main)
var {firstChild} = Parser.parse('[[file:a|none]]');
assert.deepStrictEqual(firstChild.getHorizAlignArgs(), [firstChild.lastChild]);

getVertAlignArgs

展开

returns: ImageParameterToken[]
获取图片垂直对齐参数节点。

// getVertAlignArgs (main)
var {firstChild} = Parser.parse('[[file:a|top]]');
assert.deepStrictEqual(firstChild.getVertAlignArgs(), [firstChild.lastChild]);

cloneNode

展开

returns: this
深拷贝节点。

// cloneNode (main)
var {firstChild} = Parser.parse('[[file:a]]');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);

setTarget

展开

param: string 文件目标
设置文件目标。

// setTarget (main)
var {firstChild} = Parser.parse('[[file:a]]');
firstChild.setTarget('file:b');
assert.equal(firstChild, '[[file:b]]');

hasArg

展开

param: string 参数名
returns: boolean
是否具有指定图片参数。

// hasArg (main)
var {firstChild} = Parser.parse('[[file:a|b]]');
assert(firstChild.hasArg('caption'));

removeArg

展开

param: string 参数名
移除指定图片参数。

// removeArg (main)
var {firstChild} = Parser.parse('[[file:a|link=b]]');
firstChild.removeArg('link');
assert.equal(firstChild, '[[file:a]]');

getKeys

展开

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']),
);

getValues

展开

param: string 参数名
returns: (string | true)[]
获取指定的图片参数值。

// getValues (main)
var {firstChild} = Parser.parse('[[file:a|b|c]]');
assert.deepStrictEqual(firstChild.getValues('caption'), ['b', 'c']);

setValue

展开

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]]');
⚠️ **GitHub.com Fallback** ⚠️