RedirectToken (EN) - bhsd-harry/wikiparser-node GitHub Wiki
Redirect, which is always at the very beginning of a page. This class inherits all the properties and methods of the Token class which are not repeated here.
✅ Available in the Mini and Browser versions.
🌐 Available in the Browser version.
✅ Expand
type: 'redirect'
// type
var {firstChild} = Parser.parse('#redirect [[a]]');
assert.equal(firstChild, '#redirect [[a]]');
assert.strictEqual(firstChild.type, 'redirect');
Expand
param: this
Deep clone the node.
// cloneNode (main)
var {firstChild} = Parser.parse('#redirect [[a|b]]');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);
✅ Expand
returns: LintError[]
Report potential grammar errors.
// lint
assert.deepStrictEqual(Parser.parse('#redirect [[a|b]]').firstChild.lint(), [
{
rule: 'no-ignored',
severity: 'warning',
message: 'useless link text',
startLine: 0,
startCol: 13,
startIndex: 13,
endLine: 0,
endCol: 15,
endIndex: 15,
fix: {
range: [13, 15],
text: '',
desc: 'remove',
},
},
]);
🌐 Expand
returns: string
Output in HTML format.
// print
var {firstChild} = Parser.parse('\n#redirect [[a]]\n');
assert.equal(firstChild, '\n#redirect [[a]]\n');
assert.equal(
firstChild.print(),
`<span class="wpb-redirect">
<span class="wpb-redirect-syntax">#redirect </span><span class="wpb-redirect-target">[[<span class="wpb-link-target">a</span>]]</span>
</span>`,
);
Expand
version added: 1.10.0
returns: string
Convert to HTML.
// toHtml (main)
var {firstChild} = Parser.parse('#redirect [[a#b|c]]');
assert.strictEqual(
firstChild.toHtml(),
`<ul class="redirectText"><li><a href="/wiki/A#b" title="A">A#b</a></li></ul>`,
);