-
Notifications
You must be signed in to change notification settings - Fork 2
RedirectTargetToken (EN)
Bhsd edited this page Jan 22, 2025
·
5 revisions
The target of redirect. RedirectTargetToken inherits all the properties and methods of the LinkBaseToken class which are not repeated here.
✅ Available in the Mini and Browser versions.
✅ Expand
type: 'redirect-target'
// type
var {firstChild: {lastChild}} = Parser.parse('#redirect [[a]]');
assert.equal(lastChild, '[[a]]');
assert.strictEqual(lastChild.type, 'redirect-target');
Expand
version added: 1.10.0
type: string
Link text, read-only.
// innerText (main)
var {firstChild: {lastChild}} = Parser.parse('#redirect [[a_b#a_b|b]]');
assert.equal(lastChild, '[[a_b#a_b|b]]');
assert.strictEqual(lastChild.innerText, 'A b#a_b');
✅ Expand
returns: LintError[]
Report potential grammar errors.
// lint
var {firstChild: {lastChild}} = Parser.parse('#redirect [[a|b]]');
assert.equal(lastChild, '[[a|b]]');
assert.deepStrictEqual(lastChild.lint(), [
{
rule: 'no-ignored',
severity: 'error',
message: 'useless link text',
startLine: 0,
startCol: 13,
startIndex: 13,
endLine: 0,
endCol: 15,
endIndex: 15,
fix: {
range: [13, 15],
text: '',
desc: 'remove',
},
},
]);
Expand
param: this
Deep clone the node.
// cloneNode (main)
var {firstChild: {lastChild}} = Parser.parse('#redirect [[a|b]]');
assert.equal(lastChild, '[[a|b]]');
assert.deepStrictEqual(lastChild.cloneNode(), lastChild);
Expand
param: string
Set the target page name.
// setTarget (main)
var {firstChild: {lastChild}} = Parser.parse('#redirect [[a]]');
assert.equal(lastChild, '[[a]]');
lastChild.setTarget('b');
assert.equal(lastChild, '[[b]]');
lastChild.setTarget('category:c');
assert.equal(lastChild, '[[category:c]]');
Expand
param: string
Set fragment.
// setFragment (main)
var {firstChild: {lastChild}} = Parser.parse('#redirect [[a#a]]');
assert.equal(lastChild, '[[a#a]]');
lastChild.setFragment();
// this method will normalize the target page name
assert.equal(lastChild, '[[A]]');
lastChild.setFragment('b');
assert.equal(lastChild, '[[A#b]]');
Expand
param: string
Remove the useless displayed link text.
// setLinkText (main)
var {firstChild: {lastChild}} = Parser.parse('#redirect [[a|b]]');
assert.equal(lastChild, '[[a|b]]');
lastChild.setLinkText();
assert.equal(lastChild, '[[a]]');
对维基文本批量执行语法检查的命令行工具
用于维基文本的 ESLint 插件
A command-line tool that performs linting on Wikitext in bulk
ESLint plugin for Wikitext