CommentToken (EN) - bhsd-harry/wikiparser-node GitHub Wiki
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.
✅ 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-->");✅ 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-->");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);✅ 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",
},
],
},
]);🌐 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"><!-- a --></span>',
);
assert.strictEqual(
lastChild.print(),
'<span class="wpb-comment"><!-- b</span>',
);