Constructor
new Result(html, processOptionsopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
html |
string | HTML string to be parsed. |
|
processOptions |
ProcessOptions |
<optional> |
Custom settings applied to the Result. |
Members
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
Type:
- string
html
Current Root as a String.
messages :Array.<Message>
List of the messages gathered during transformations
Type:
- Array.<Message>
root :Node
Root Node
Type:
to :string
Path to the HTML output file
Type:
- string
type :'result'
Type identifier of the Result
Type:
- 'result'
visitors :Object.<string, Array.<function()>>
Normalized plugins and visitors
Type:
- Object.<string, Array.<function()>>
voidElements :Array.<string>
List of the elements that only have a start tag, as they cannot have any content
Type:
- Array.<string>
warnings
Messages that are warnings.
Methods
normalize(nodeopt)
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}
Current Root as an Object.
Returns:
- Type
- Object
visit(node, overrideVisitorsopt) → {ResultPromise}
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)
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. |