-
Notifications
You must be signed in to change notification settings - Fork 2
LinkToken (EN)
bhsd edited this page Jul 11, 2024
·
16 revisions
Table of Contents
Internal link, including interwiki link. LinkToken inherits all the properties and methods of the LinkBaseToken class which are not repeated here.
✅ Available in the Mini and Browser versions.
✅ Expand
type: 'link'
// type
var {firstChild} = Parser.parse('[[:category:a]]');
assert.strictEqual(firstChild.type, 'link');
Expand
type: string
Displayed link text.
// innerText (main)
var {firstChild, lastChild} = Parser.parse([[ : %3f ]][[b| c ]]');
assert.equal(firstChild, '[[ : %3f ]]');
assert.equal(lastChild, '[[b| c ]]');
assert.strictEqual(firstChild.innerText, ' ? ');
assert.strictEqual(lastChild.innerText, ' c ');
firstChild.innerText = 'd';
assert.equal(firstChild, '[[ : %3f |d]]');
Expand
type: boolean
Whether the link is a self-link.
// selfLink (main)
var {firstChild, lastChild} = Parser.parse([[a#a]][[##]]');
assert.equal(firstChild, '[[a#a]]');
assert.equal(lastChild, '[[##]]');
assert(!firstChild.selfLink);
assert(lastChild.selfLink);
firstChild.selfLink = true;
assert.equal(firstChild, '[[#a]]');
✅ Expand
returns: LintError[]
Report potential grammar errors.
// lint
var {firstChild: {lastChild}} = Parser.parse('[//a [[b]]]');
assert.equal(lastChild, '[[b]]');
assert.deepStrictEqual(lastChild.lint(), [
{
rule: 'nested-link',
severity: 'error',
message: 'internal link in an external link',
startLine: 0,
startCol: 5,
startIndex: 5,
endLine: 0,
endCol: 10,
endIndex: 10,
},
]);
Expand
returns: this
Deep clone the node.
// cloneNode (main)
var {firstChild} = Parser.parse('[[a#b|c]]');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);
Expand
param: string
param: string
Set inter-language link.
// setLangLink (main)
var firstChild;
// Interwiki prefixes depend on the specific settings of each MediaWiki site
Parser.config = 'moegirl';
({firstChild} = Parser.parse('[[a]]'));
firstChild.setLangLink('en', 'b#c');
assert.equal(firstChild, '[[en:b#c]]');
Expand
param: string
Convert the link to a self-link.
// asSelfLink (main)
var {firstChild} = Parser.parse('[[a#b]]');
firstChild.asSelfLink();
assert.equal(firstChild, '[[#b]]');
firstChild.asSelfLink('[');
assert.equal(firstChild, '[[#%5B]]');
Expand
Automatically generate the link text after the pipe.
// pipeTrick (main)
var {children: [a, b, c, d]} = Parser.parse(`[[:file: a (a), a]]
[[:user: b (b)]]
[[:talk: c , c]]
[[:help: d (d) ]]`);
assert.equal(a, '[[:file: a (a), a]]');
assert.equal(b, '[[:user: b (b)]]');
assert.equal(c, '[[:talk: c , c]]');
assert.equal(d, '[[:help: d (d) ]]');
a.pipeTrick();
assert.equal(a, '[[:file: a (a), a| a ]]');
b.pipeTrick();
assert.equal(b, '[[:user: b (b)| b ]]');
c.pipeTrick();
assert.equal(c, '[[:talk: c , c| c ]]');
d.pipeTrick();
assert.equal(d.toString(), '[[:help: d (d) | d (d) ]]');
对维基文本批量执行语法检查的命令行工具
用于维基文本的 ESLint 插件
A command-line tool that performs linting on Wikitext in bulk
ESLint plugin for Wikitext