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

Other Languages

Introduction

External link wrapped by []. This class mixes the properties and methods of the MagicLinkToken class, and inherits all the properties and methods of the Token class which are not repeated here.

All of the following properties and methods are not available in the Mini and Browser versions.

Properties

innerText

Expand

type: string
Display text of the external link.

// innerText (main)
var {firstChild, lastChild} = Parser.parse('[//a][//b bb]');
assert.equal(firstChild, '[//a]');
assert.equal(lastChild, '[//b bb]');
assert.strictEqual(firstChild.innerText, '[1]');
assert.strictEqual(lastChild.innerText, 'bb');
firstChild.innerText = 'a';
assert.equal(firstChild, '[//a a]');

Methods

cloneNode

Expand

returns: this
Deep clone the node.

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

setLinkText

Expand

param: string display text
Set the display text of the external link.

// setLinkText (main)
var {firstChild} = Parser.parse('[//a]');
firstChild.setLinkText('a');
assert.equal(firstChild, '[//a a]');

toHtml

Expand

version added: 1.10.0

returns: string
Convert to HTML.

// toHtml (main)
var root = Parser.parse('[//a][news:b b ]');
root.type = 'plain';
assert.strictEqual(
	root.toHtml(),
	`<a rel="nofollow" class="external" href="https://a/">[1]</a><a rel="nofollow" class="external" href="news:b">b </a>`,
);
root = Parser.parse('[//a [[b]]c]');
root.type = 'plain';
assert.strictEqual(
	root.toHtml(),
	'<a rel="nofollow" class="external" href="https://a/"></a>',
);
⚠️ **GitHub.com Fallback** ⚠️