Result

Result

Return a new syntax tree Result from a processed input.

Constructor

new Result(html, processOptionsopt)

Source:
Parameters:
Name Type Attributes Description
html string

HTML string to be parsed.

processOptions ProcessOptions <optional>

Custom settings applied to the Result.

Members

from :string

Source:

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

Type:
  • string

html

Source:

Current Root as a String.

messages :Array.<Message>

Source:

List of the messages gathered during transformations

Type:

root :Node

Source:

Root Node

Type:

to :string

Source:

Path to the HTML output file

Type:
  • string

type :'result'

Source:

Type identifier of the Result

Type:
  • 'result'

visitors :Object.<string, Array.<function()>>

Source:

Normalized plugins and visitors

Type:
  • Object.<string, Array.<function()>>

voidElements :Array.<string>

Source:

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

Type:
  • Array.<string>

warnings

Source:

Messages that are warnings.

Methods

normalize(nodeopt)

Source:

Return a normalized node whose instances match the current Result.

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

Node to be normalized.

toJSON() → {Object}

Source:

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

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

Message being sent as the warning.

opts Object <optional>

Additional information about the warning.