RedirectToken (EN) - bhsd-harry/wikiparser-node GitHub Wiki

Other Languages

Introduction

Redirect, which is always at the very beginning of a page. RedirectToken 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.

Properties

type

✅ Expand

type: 'redirect'

// type
var {firstChild} = Parser.parse('#redirect [[a]]');
assert.equal(firstChild, '#redirect [[a]]');
assert.strictEqual(firstChild.type, 'redirect');

Methods

text

✅ Expand

returns: string
Redirect is invisible.

// text
var {firstChild} = Parser.parse('#redirect [[a]]');
assert.strictEqual(firstChild.text(), '');

print

🌐 Expand

returns: string
Output in HTML format.

// print
var {firstChild} = Parser.parse('\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>`,
);

cloneNode

Expand

param: this
Deep clone the node.

// cloneNode (main)
var {firstChild} = Parser.parse('#redirect [[a|b]]');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);

toHtml

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