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

Other Languages

Introduction

HTML comment.

✅ Available in the Mini and Browser versions.

Properties

closed

✅ Expand

type: boolean
Whether the comment is closed.

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

innerText

✅ Expand

type: string
The text content of the comment.

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

hidden

Expand

type: true
CommentToken is invisible, read-only.

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

Methods

lint

✅ Expand

returns: LintError[]
Report potential grammar errors.

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

cloneNode

Expand

returns: this
Deep clone the node.

// cloneNode (main)
var {firstChild, lastChild} = Parser.parse('<!--a--><!--b'),
	closed = firstChild.cloneNode(),
	open = lastChild.cloneNode();
assert.equal(firstChild, '<!--a-->');
assert.equal(closed, '<!--a-->');
assert.equal(lastChild, '<!--b');
assert.equal(open, '<!--b');
assert.deepStrictEqual(closed, firstChild);
assert.deepStrictEqual(open, lastChild);
⚠️ **GitHub.com Fallback** ⚠️