# hast-util-from-parse5
[![Build][badge-build-image]][badge-build-url]
[![Coverage][badge-coverage-image]][badge-coverage-url]
[![Downloads][badge-downloads-image]][badge-downloads-url]
[![Size][badge-size-image]][badge-size-url]
[hast][github-hast] utility to transform from the
[`parse5`][github-parse5] AST.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`fromParse5(tree[, options])`](#fromparse5tree-options)
* [`Options`](#options)
* [`Space`](#space-1)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package is a utility that can turn a parse5 tree into a hast tree.
## When should I use this?
You can use this package when using `parse5` as an HTML parser and wanting to
work with hast.
The utility [`hast-util-to-parse5`][github-hast-util-to-parse5] does the
inverse of this utility.
It generates `parse5`s AST again.
The utility [`hast-util-from-html`][github-hast-util-from-html] wraps this
utility and `parse5` to both parse HTML and generate hast from it.
## Install
This package is [ESM only][github-gist-esm].
In Node.js (version 16+),
install with [npm][npmjs-install]:
```sh
npm install hast-util-from-parse5
```
In Deno with [`esm.sh`][esmsh]:
```js
import {fromParse5} from "https://esm.sh/hast-util-from-parse5@8"
```
In browsers with [`esm.sh`][esmsh]:
```html
```
## Use
Say our document `example.html` contains:
```html
[3] (1:37-2:1, 36-70)
│ properties: {"id":"world"}
├─0 text "World!" (1:52-1:58, 51-57)
├─1 comment "after" (1:58-1:70, 57-69)
└─2 text "\n" (1:70-2:1, 69-70)
```
## API
This package exports the identifier [`fromParse5`][api-from-parse5].
There is no default export.
### `fromParse5(tree[, options])`
Transform a `parse5` AST to hast.
###### Parameters
* `tree`
([`Parse5Node`][github-parse5-node])
— `parse5` tree to transform
* `options`
([`Options`][api-options], optional)
— configuration
###### Returns
hast tree ([`HastNode`][github-hast-nodes]).
### `Options`
Configuration (TypeScript type).
##### Fields
###### `file`
File used to add positional info to nodes
([`VFile`][github-vfile], optional).
If given,
the file should represent the original HTML source.
###### `space`
Which space the document is in
([`Space`][api-space], default: `'html'`).
When an `