# x-domhandler

> handler for htmlparser2 that turns pages into a dom

Latest version **2.4.2** (published 2018-08-19) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install x-domhandler
pnpm add x-domhandler
yarn add x-domhandler
bun add x-domhandler
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.4.2 |
| Published | 2018-08-19 |
| First published | 2018-08-19 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 29.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Felix Boehm |
| Maintainers | yanghuabei |
| Keywords | dom, htmlparser2 |

## Links

- npm: https://www.npmjs.com/package/x-domhandler
- Repository: https://github.com/yanghuabei/DomHandler
- Homepage: https://github.com/yanghuabei/DomHandler#readme
- Issues: https://github.com/yanghuabei/DomHandler/issues
- npm.io page: https://npm.io/package/x-domhandler

## Dependencies (1)

- [domelementtype](https://npm.io/package/domelementtype.md) 1

## 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

- 2.4.2 (latest) — 2018-08-19

## README

# domhandler [![Build Status](https://travis-ci.org/yanghuabei/domhandler.svg?branch=master)](https://travis-ci.org/yanghuabei/domhandler)

The DOM handler (formally known as DefaultHandler) creates a tree containing all nodes of a page. The tree may be manipulated using the [domutils](https://github.com/fb55/domutils) library.

## Differences with origin domhandler
1. Add `selfClose` flag to node.
2. Add `singleQuoteAttribs` map to node.

This project can work with [stricter-htmlparser2](https://github.com/yanghuabei/htmlparser2).

## Usage
```javascript
var handler = new DomHandler([ <func> callback(err, dom), ] [ <obj> options ]);
// var parser = new Parser(handler[, options]);
```

Available options are described below.

## Example
```javascript
var htmlparser = require("htmlparser2");
var rawHtml = "Xyz <script language= 'javascript'>var foo = '<<bar>>';< /  script><!--<!-- Waah! -- -->";
var handler = new htmlparser.DomHandler(function (error, dom) {
    if (error)
    	[...do something for errors...]
    else
    	[...parsing done, do something...]
        console.log(dom);
});
var parser = new htmlparser.Parser(handler);
parser.write(rawHtml);
parser.end();
```

Output:

```javascript
[{
    data: 'Xyz ',
    type: 'text'
}, {
    type: 'script',
    name: 'script',
    attribs: {
    	language: 'javascript'
    },
    children: [{
    	data: 'var foo = \'<bar>\';<',
    	type: 'text'
    }]
}, {
    data: '<!-- Waah! -- ',
    type: 'comment'
}]
```

## Option: normalizeWhitespace
Indicates whether the whitespace in text nodes should be normalized (= all whitespace should be replaced with single spaces). The default value is "false". 

The following HTML will be used:

```html
<font>
	<br>this is the text
<font>
```

### Example: true

```javascript
[{
    type: 'tag',
    name: 'font',
    children: [{
    	data: ' ',
    	type: 'text'
    }, {
    	type: 'tag',
    	name: 'br'
    }, {
    	data: 'this is the text ',
    	type: 'text'
    }, {
    	type: 'tag',
    	name: 'font'
    }]
}]
```

### Example: false

```javascript
[{
    type: 'tag',
    name: 'font',
    children: [{
    	data: '\n\t',
    	type: 'text'
    }, {
    	type: 'tag',
    	name: 'br'
    }, {
    	data: 'this is the text\n',
    	type: 'text'
    }, {
    	type: 'tag',
    	name: 'font'
    }]
}]
```

## Option: withDomLvl1

Adds DOM level 1 properties to all elements.

<!-- TODO: description -->

## Option: withStartIndices
Indicates whether a `startIndex` property will be added to nodes. When the parser is used in a non-streaming fashion, `startIndex` is an integer indicating the position of the start of the node in the document. The default value is "false".

## Option: withEndIndices
Indicates whether a `endIndex` property will be added to nodes. When the parser is used in a non-streaming fashion, `endIndex` is an integer indicating the position of the end of the node in the document. The default value is "false".

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