ExtLinkToken - bhsd-harry/wikiparser-node GitHub Wiki

Other Languages

简介

[]内的外部链接。这个类同时混合了 MagicLinkToken 类的属性和方法。

以下所有属性和方法在 MiniBrowser 版本中均不可用。

Properties

innerText

type: string
链接显示文字。

// 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
深拷贝节点。

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

setLinkText

param: string 链接显示文字
设置链接显示文字。

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

toHtml

加入的版本: 1.10.0

returns: string
转换为 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`,
);