Comment

Comment

Return a new Comment Node.

Constructor

new Comment(settings) → {Comment}

Source:
Example
new Comment({ comment: ' Hello World ' })
Parameters:
Name Type Description
settings Object | String

Custom settings applied to the Comment, or the content of the Comment.

Properties
Name Type Description
comment String

Content of the Comment.

source Object

Source mapping of the Comment.

Returns:
Type
Comment

Extends

Members

index

Source:
Inherited From:

The position of the current Node from its parent.

Example
node.index // returns the index of the node or -1

innerHTML

Source:

Return the stringified innerHTML of the current Comment.

Example
attrs.innerHTML // returns ' Hello World '

next

Source:
Inherited From:

The next Node after the current Node, or null if there is none.

Example
node.next // returns null

nextElement

Source:
Inherited From:

The next Element after the current Node, or null if there is none.

Example
node.nextElement // returns an element or null

outerHTML

Source:

Return the stringified outerHTML of the current Comment.

Example
attrs.outerHTML // returns '<!-- Hello World -->'

previous

Source:
Inherited From:

The previous Node before the current Node, or null if there is none.

Example
node.previous // returns a node or null

previousElement

Source:
Inherited From:

The previous Element before the current Node, or null if there is none.

Example
node.previousElement // returns an element or null

root

Source:
Inherited From:

The top-most ancestor from the current Node.

Example
node.root // returns the top-most node or the current node itself

sourceInnerHTML

Source:

Return the stringified innerHTML from the source input.

Example
attrs.sourceInnerHTML // returns ' Hello World '

sourceOuterHTML

Source:

Return the stringified outerHTML from the source input.

Example
attrs.sourceOuterHTML // returns '<!-- Hello World -->'

Methods

after(…nodes) → {Node}

Source:
Inherited From:

Insert one ore more Nodes after the current Node.

Example
node.after(new Text({ data: 'Hello World' }))
Parameters:
Name Type Attributes Description
nodes Node | String <repeatable>

Any nodes to be inserted after the current Node.

Returns:
Type
Node

append(…nodes) → {Node}

Source:
Inherited From:

Append Nodes or new Text Nodes to the current Node.

Example
node.append(someOtherNode)
Parameters:
Name Type Attributes Description
nodes Node | String <repeatable>

Any nodes to be inserted after the last child of the current Node.

Returns:
Type
Node

appendTo(parent) → {Node}

Source:
Inherited From:

Append the current Node to another Node.

Parameters:
Name Type Description
parent Container

The Container for the current Node.

Returns:
Type
Node

before(…nodes) → {Node}

Source:
Inherited From:

Insert Nodes or new Text Nodes before the Node if it has a parent.

Example
node.before(new Text({ data: 'Hello World' })) // returns the current node
Parameters:
Name Type Attributes Description
nodes Node | String <repeatable>

Any nodes to be inserted before the current Node.

Returns:
Type
Node

clone(settings) → {Comment}

Source:

Return a clone of the current Comment.

Examples
comment.clone()

Clone the current text with new source.

comment.clone({ source: { input: 'modified source' } })
Parameters:
Name Type Description
settings Object

Custom settings applied to the cloned Comment.

Returns:
Type
Comment

prepend(…nodes) → {Node}

Source:
Inherited From:

Prepend Nodes or new Text Nodes to the current Node.

Example
node.prepend(someOtherNode)
Parameters:
Name Type Attributes Description
nodes Node | String <repeatable>

Any nodes inserted before the first child of the current Node.

Returns:
Type
Node

remove() → {Node}

Source:
Inherited From:

Remove the current Node from its parent.

Example
node.remove() // returns the current node
Returns:
Type
Node

replaceWith(…nodes) → {Node}

Source:
Inherited From:

Replace the current Node with another Node or Nodes.

Example
node.replaceWith(someOtherNode) // returns the current node
Parameters:
Name Type Attributes Description
nodes Node <repeatable>

Any nodes replacing the current Node.

Returns:
Type
Node

toJSON() → {Object}

Source:

Return the current Comment as a Object.

Example
attrs.toJSON() // returns { comment: ' Hello World ' }
Returns:

An object version of the current Comment

Type
Object

toString() → {String}

Source:

Return the current Comment as a String.

Example
attrs.toJSON() // returns '<!-- Hello World -->'
Returns:

A string version of the current Comment

Type
String

visit(result, overrideVisitorsopt) → {ResultPromise}

Source:
Inherited From:

Transform the current Node and any descendants using visitors.

Examples
await node.visit(result)
await node.visit() // visit using the result of the current node
await node.visit(result, {
  Element () {
    // do something to an element
  }
})
Parameters:
Name Type Attributes Description
result Result

The Result to be used by visitors.

overrideVisitors Object <optional>

Alternative visitors to be used in place of Result visitors.

Returns:
Type
ResultPromise

warn(result, text, optsopt)

Source:
Inherited From:

Add a warning from the current Node.

Examples
node.warn(result, 'Something went wrong')
node.warn(result, 'Something went wrong', {
  node: someOtherNode,
  plugin: someOtherPlugin
})
Parameters:
Name Type Attributes Description
result Result

The Result the warning is being added to.

text String

The message being sent as the warning.

opts Object <optional>

Additional information about the warning.