IncludeToken - bhsd-harry/wikiparser-node GitHub Wiki

Other Languages

简介

非嵌入时为被<includeonly></includeonly>包裹的内容,嵌入时为被<noinclude></noinclude>包裹的内容。这个类继承了 TagPairToken 类的全部属性和方法,这里不再列出。

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

Properties

TagPairToken 继承的属性

innerText

✅ 展开

type: string
标签内的文本内容。

// innerText (main)
var {firstChild} = Parser.parse('<includeonly>a</includeonly>');
firstChild.innerText = 'b';
assert.equal(firstChild, '<includeonly>b</includeonly>');
firstChild.innerText = undefined;
assert.equal(firstChild, '<includeonly/>');

Methods

TagPairToken 继承的方法

cloneNode

展开

returns: this
深拷贝节点。

// cloneNode (main)
var {
	childNodes: [closed, selfClosing, open],
} = Parser.parse('<includeonly>a</includeonly><includeonly/><includeonly>b');
assert.equal(closed, '<includeonly>a</includeonly>');
assert.equal(selfClosing, '<includeonly/>');
assert.equal(open, '<includeonly>b');
assert.deepStrictEqual(closed.cloneNode(), closed);
assert.deepStrictEqual(selfClosing.cloneNode(), selfClosing);
assert.deepStrictEqual(open.cloneNode(), open);

lint

✅ 展开

returns: LintError[]
报告潜在语法错误。

// lint
var include = Parser.parse('<includeonly name=a>a');
assert.equal(include, '<includeonly name=a>a');
assert.deepStrictEqual(include.lint(), [
	{
		rule: 'no-ignored',
		severity: 'warning',
		message: 'useless attribute',
		startLine: 0,
		startCol: 12,
		startIndex: 12,
		endLine: 0,
		endCol: 19,
		endIndex: 19,
		suggestions: [
			{
				desc: 'remove',
				range: [12, 19],
				text: '',
			},
		],
	},
	{
		rule: 'unclosed-comment',
		severity: 'warning',
		message: 'unclosed <includeonly>',
		startLine: 0,
		startCol: 0,
		startIndex: 0,
		endLine: 0,
		endCol: 21,
		endIndex: 21,
		suggestions: [
			{
				desc: 'close',
				range: [21, 21],
				text: '</includeonly>',
			},
		],
	},
]);

removeAttr

展开

清除标签属性。<includeonly>标签的属性没有任何效果。

// removeAttr (main)
var {firstChild} = Parser.parse('<includeonly name="a">a</includeonly>');
assert.equal(firstChild, '<includeonly name="a">a</includeonly>');
firstChild.removeAttr();
assert.equal(firstChild, '<includeonly>a</includeonly>');

setText

展开

param: string 新文本
设置标签内的文本内容。

// setText (main)
var {firstChild} = Parser.parse('<includeonly>a</includeonly>');
assert.equal(firstChild, '<includeonly>a</includeonly>');
firstChild.setText('b');
assert.equal(firstChild, '<includeonly>b</includeonly>');
⚠️ **GitHub.com Fallback** ⚠️