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.
All of the following properties and methods are not available in the Mini and Browser versions.
Properties
innerText
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
returns: this
Deep clone the node.
// cloneNode (main)
var {firstChild} = Parser.parse('[//a b]');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);
setLinkText
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
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](/bhsd-harry/wikiparser-node/wiki/b)c]');
root.type = 'plain';
assert.strictEqual(
root.toHtml(),
`<a rel="nofollow" class="external" href="https://a/"></a><a href="/wiki/B" title="B">b</a>c`,
);