Skip to content

ImageParameterToken (EN)

bhsd edited this page Jun 3, 2024 · 9 revisions
Table of Contents

Other Languages

Introduction

Image parameter.

✅ Available in the Mini and Browser versions.

Properties

name

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

link

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

value

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

size

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

width

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

height

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

Methods

lint

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

getValue

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

cloneNode

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

setValue

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');
Clone this wiki locally