# @starptech/hast-util-from-webparser

> Produce [HAST](https://github.com/syntax-tree/hast) compatible AST from [Webparser](https://github.com/Prettyhtml/prettyhtml/tree/master/packages/webparser)

Latest version **0.10.0** (published 2019-06-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @starptech/hast-util-from-webparser
pnpm add @starptech/hast-util-from-webparser
yarn add @starptech/hast-util-from-webparser
bun add @starptech/hast-util-from-webparser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.10.0 |
| Published | 2019-06-21 |
| First published | 2018-09-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 70.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dustin Deus |
| Maintainers | starptech |
| Keywords | formatter, webparser, hast, html5 |

## Links

- npm: https://www.npmjs.com/package/@starptech/hast-util-from-webparser
- npm.io page: https://npm.io/package/@starptech/hast-util-from-webparser

## Dependencies (3)

- [@starptech/webparser](https://npm.io/package/@starptech/webparser.md) ^0.10.0
- [property-information](https://npm.io/package/property-information.md) ^5.1.0
- [@starptech/prettyhtml-hastscript](https://npm.io/package/@starptech/prettyhtml-hastscript.md) ^0.10.0

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 0.10.0 (latest) — 2019-06-21
- 0.9.0 — 2019-04-28
- 0.8.17 — 2019-04-07
- 0.8.10 — 2018-12-09
- 0.8.7 — 2018-12-06
- 0.8.6 — 2018-12-04
- 0.8.5 — 2018-11-28
- 0.8.3 — 2018-11-24
- 0.8.1 — 2018-11-12
- 0.8.0 — 2018-11-11
- 0.7.0 — 2018-11-10
- 0.6.0 — 2018-11-08
- 0.5.3 — 2018-11-08
- 0.5.2 — 2018-11-06
- 0.5.0 — 2018-10-28
- … 19 more at https://npm.io/package/@starptech/hast-util-from-webparser/versions

## README

# @starptech/hast-util-from-webparser

Produce [HAST](https://github.com/syntax-tree/hast) compatible AST from [Webparser](https://github.com/Prettyhtml/prettyhtml/tree/master/packages/webparser)

## Installation

```
@starptech/hast-util-from-webparser
```

## Usage

Say we have the following file, `example.html`:

```html
<!DOCTYPE html><title>Hello!</title>
<h1 id="world">World!<!--after--></h1>
```

And our script, `example.js`, looks as follows:

```javascript
const vfile = require('to-vfile')
const inspect = require('unist-util-inspect')
const HtmlParser = require('@starptech/webparser').HtmlParser
const fromWebparser = require('@starptech/hast-util-from-webparser')

const filepath = 'example.html'
const doc = vfile.readSync(filepath)
const result = new HtmlParser({
  ignoreFirstLf: false,
  decodeEntities: false,
  selfClosingCustomElements: true
}).parse(String(doc), filepath)

const hast = fromWebparser(result.rootNodes)
```

Now, running `node example` yields:

```text
root[3] [data={"selfClosing":false}]
├─ doctype (1:1-1:15, 0-15) [name="html"]
├─ element[1] (1:15-1:36, 15-36) [tagName="title"][data={"selfClosing":false}]
│  └─ text: "Hello!" (1:22-1:28, 22-28)
└─ element[2] [tagName="h1"][properties={"id":"world"}][data={"selfClosing":false}]
   ├─ text: "World!" (1:51-1:57, 51-57)
   └─ comment: "after" (1:57-1:61, 57-61)
```

## API

### `fromWebparser(rootNodes[, options])`

Transform an `Node` to a [**HAST Node**](https://github.com/syntax-tree/hast#ast).

---
_Source: https://npm.io/package/@starptech/hast-util-from-webparser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
