# @starptech/webparser

> Optimized html parser for HTML5 Web Components.

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

## Install

```sh
npm install @starptech/webparser
pnpm add @starptech/webparser
yarn add @starptech/webparser
bun add @starptech/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-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 170.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dustin Deus |
| Maintainers | starptech |
| Keywords | formatter, webparser, parser, htmlparser, html5 |

## Links

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

## 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.5 — 2018-11-28
- 0.8.3 — 2018-11-24
- 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
- 0.4.2 — 2018-10-27
- 0.4.1 — 2018-10-26
- 0.4.0 — 2018-10-26
- … 15 more at https://npm.io/package/@starptech/webparser/versions

## README

# @starptech/webparser

Optimized html parser for HTML5 Web Components.
The parser supports features which are very useful if you want to implement a HTML formatter or anything else where a less strict parser is needed to keep all informations in the ast.

## Installation

```
npm install --save @starptech/webparser
```

## Usage

This example shows how we parse HTML

```js
const parser = new HtmlParser(options)
const result = parser.parse('<div></div>')
```

## Representation

There are four different types of nodes

- Doctype

```js
{
  value: '<!doctype html>',
  sourceSpan: null
}
```

- Element

```js
{
  name: 'div',
  attrs: [],
  children: [],
  implicitNs: false,
  sourceSpan: null,
  startSourceSpan: null,
  endSourceSpan
}
```

Void or self-closing elements can be checked when the `startSourceSpan` is equals the `endSourceSpan`.

- Attribute

```js
{
  name: 'div',
  value: 'foo',
  children: [],
  implicitNs: false,
  sourceSpan:null,
  valueSpan: null
}
```

- Comment

```js
{
  value: 'foo comment',
  sourceSpan: null
}
```

## API

##### `HtmlParser.parse(doc: string): ParseTreeResult`

Parse a document and returns a `ParseTreeResult` result.

###### `options.decodeEntities` (enabled by default)

Decode html entities in text and attributes according to HTML5 specification.

###### `options.ignoreFirstLf` (enabled by default)

Ignore first line feed of `pre`, `textarea` and `listing` tags according to HTML5 specification.

###### `options.selfClosingCustomElements` (disabled by default)

Allow custom self-closing elements.

###### `options.selfClosingElements` (disabled by default)

Allow custom and known self closing HTML elements.

###### `options.insertRequiredParents` (disabled by default)

Insert the required parent element according to the HTML5 specification.

## Credits

The parser is a modificated version of [Angular 6](https://github.com/angular/angular) template parser.

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