IncludeToken - bhsd-harry/wikiparser-node GitHub Wiki

目录

Other Languages

简介

非嵌入时为被<includeonly></includeonly>包裹的内容,嵌入时为被<noinclude></noinclude>包裹的内容。

✅ 在 MiniBrowser 版本中可用。

Properties

name

✅ 展开

type: string
标签名,只读。

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

closed

✅ 展开

type: boolean
是否闭合。

// closed
var {firstChild} = Parser.parse('<includeonly>a');
assert.equal(firstChild, '<includeonly>a');
assert(!firstChild.closed);
firstChild.closed = true;
assert.equal(firstChild, '<includeonly>a</includeonly>');

selfClosing

✅ 展开

type: boolean
是否自封闭。

// selfClosing
var {firstChild} = Parser.parse('<includeonly>a</includeonly>');
assert.equal(firstChild, '<includeonly>a</includeonly>');
assert(!firstChild.selfClosing);
firstChild.selfClosing = true;
assert.equal(firstChild, '<includeonly/>');

innerText

✅ 展开

type: string
内部 wikitext。

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

hidden

展开

type: true
IncludeToken 不可见,只读。

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

Methods

lint

✅ 展开

加入的版本: 1.3.2

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

// lint
var include = Parser.parse('<includeonly>a');
assert.equal(include, '<includeonly>a');
assert.deepEqual(include.lint(), [
	{
		rule: 'unclosed-comment',
		severity: 'error',
		message: 'unclosed <includeonly>',
		startLine: 0,
		startCol: 0,
		startIndex: 0,
		endLine: 0,
		endCol: 14,
		endIndex: 14,
		suggestions: [
			{
				desc: 'close',
				range: [14, 14],
				text: '</includeonly>',
			},
		],
	},
]);

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);

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>');
⚠️ **GitHub.com Fallback** ⚠️