Skip to content

OnlyincludeToken

bhsd edited this page Jun 21, 2024 · 13 revisions

Other Languages

简介

<onlyinclude></onlyinclude>包裹的内容。仅在嵌入时(即 Parser.parse(text, true))生效。

✅ 在 MiniBrowser 版本中可用。
🌐 在 Browser 版本中可用。

Properties

type

✅ 展开

type: 'onlyinclude'

// type
var {firstChild} = Parser.parse('<onlyinclude>a</onlyinclude>', true);
assert.equal(firstChild, '<onlyinclude>a</onlyinclude>');
assert.strictEqual(firstChild.type, 'onlyinclude');

innerText

type: string
内部wikitext。

// innerText (main)
var {firstChild} = Parser.parse('<onlyinclude>a</onlyinclude>', true);
assert.equal(firstChild, '<onlyinclude>a</onlyinclude>');
assert.strictEqual(firstChild.innerText, 'a');
firstChild.innerText = '[[a]]';
assert.equal(firstChild, '<onlyinclude>[[a]]</onlyinclude>');
assert.strictEqual(firstChild.firstChild.type, 'link');

Methods

print

🌐 展开

returns: string
以HTML格式输出。

// print
var {firstChild} = Parser.parse('<onlyinclude>a</onlyinclude>', true);
assert.equal(
	firstChild.print(),
	`<span class="wpb-onlyinclude"><span class="wpb-ext">&lt;onlyinclude&gt;</span>a<span class="wpb-ext">&lt;/onlyinclude&gt;</span></span>`,
);

cloneNode

returns: this
深拷贝节点。

// cloneNode (main)
var {firstChild} = Parser.parse('<onlyinclude>a</onlyinclude>', true);
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);
Clone this wiki locally