CommentToken (EN) - bhsd-harry/wikiparser-node GitHub Wiki

Other Languages

Introduction

HTML comment. This class inherits all the properties and methods of the Token class which are not repeated here.

✅ Available in the Mini and Browser versions.
🌐 Available in the Browser version.

Properties

closed

✅ Expand

type: boolean
Whether the comment is closed.

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

innerText

✅ Expand

type: string
The text content of the comment. Read-only in the Mini and Browser versions.

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

Methods

cloneNode

Expand

returns: this
Deep clone the node.

// cloneNode (main)
var {firstChild, lastChild} = Parser.parse("<!--a--><!--b");
assert.equal(firstChild, "<!--a-->");
assert.equal(lastChild, "<!--b");
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);
assert.deepStrictEqual(lastChild.cloneNode(), lastChild);

lint

✅ Expand

returns: LintError[]
Report potential grammar errors.

// lint
var {firstChild} = Parser.parse("<!--");
assert.equal(firstChild, "<!--");
assert.deepStrictEqual(firstChild.lint(), [
	{
		rule: "unclosed-comment",
		severity: "warning",
		message: "unclosed HTML comment",
		startLine: 0,
		startCol: 0,
		startIndex: 0,
		endLine: 0,
		endCol: 4,
		endIndex: 4,
		suggestions: [
			{
				range: [4, 4],
				text: "-->",
				desc: "close",
			},
		],
	},
]);

print

🌐 Expand

returns: string
Output in HTML format.

// print (print)
var {firstChild, lastChild} = Parser.parse("<!-- a --><!-- b");
assert.equal(firstChild, "<!-- a -->");
assert.equal(lastChild, "<!-- b");
assert.strictEqual(
	firstChild.print(),
	'<span class="wpb-comment">&lt;!-- a --&gt;</span>',
);
assert.strictEqual(
	lastChild.print(),
	'<span class="wpb-comment">&lt;!-- b</span>',
);
⚠️ **GitHub.com Fallback** ⚠️