Result

Result

Create a new syntax tree Result from a processed input.

Constructor

new Result(processOptions) → {Result}

Source:
Properties:
Name Type Description
result Result

Result of pHTML transformations.

Properties
Name Type Description
from String

Path to the HTML source file. You should always set from, because it is used in source map generation and syntax error messages.

to String

Path to the HTML output file.

root Fragment

Object representing the parsed nodes of the HTML file.

messages Array

List of the messages gathered during transformations.

voidElements Array

List of the elements that only have a start tag, as they cannot have any content.

Parameters:
Name Type Description
processOptions Object

Custom settings applied to the Result.

Properties
Name Type Description
from String

Source input location.

to String

Destination output location.

voidElements Array

Void elements.

Returns:
Type
Result

Members

html

Source:

Current Root as a String.

warnings

Source:

Messages that are warnings.

Methods

normalize(nodeopt) → {Node}

Source:

Return a normalized node whose instances match the current Result.

Example
result.normalize(someNode)
Parameters:
Name Type Attributes Description
node Node <optional>

the node to be normalized.

Returns:
Type
Node

toJSON() → {Object}

Source:

The current Root as an Object.

Returns:
Type
Object

visit(node, overrideVisitorsopt) → {ResultPromise}

Source:

Transform the current Node and any descendants using visitors.

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

The Node to be visited.

overrideVisitors Object <optional>

Alternative visitors to be used in place of Result visitors.

Returns:
Type
ResultPromise

warn(text, optsopt)

Source:

Add a warning to the current Root.

Examples
result.warn('Something went wrong')
result.warn('Something went wrong', {
  node: someNode,
  plugin: somePlugin
})
Parameters:
Name Type Attributes Description
text String

The message being sent as the warning.

opts Object <optional>

Additional information about the warning.