1 # domhandler [![Build Status](https://travis-ci.org/fb55/domhandler.svg?branch=master)](https://travis-ci.org/fb55/domhandler)
3 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.
7 var handler = new DomHandler([ <func> callback(err, dom), ] [ <obj> options ]);
8 // var parser = new Parser(handler[, options]);
11 Available options are described below.
15 var htmlparser = require("htmlparser2");
16 var rawHtml = "Xyz <script language= javascript>var foo = '<<bar>>';< / script><!--<!-- Waah! -- -->";
17 var handler = new htmlparser.DomHandler(function (error, dom) {
19 [...do something for errors...]
21 [...parsing done, do something...]
24 var parser = new htmlparser.Parser(handler);
25 parser.write(rawHtml);
39 language: 'javascript'
42 data: 'var foo = \'<bar>\';<',
46 data: '<!-- Waah! -- ',
51 ## Option: normalizeWhitespace
52 Indicates whether the whitespace in text nodes should be normalized (= all whitespace should be replaced with single spaces). The default value is "false".
54 The following HTML will be used:
75 data: 'this is the text ',
97 data: 'this is the text\n',
106 ## Option: withDomLvl1
108 Adds DOM level 1 properties to all elements.
110 <!-- TODO: description -->
112 ## Option: withStartIndices
113 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".
115 ## Option: withEndIndices
116 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".