.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / domhandler / readme.md
1 # domhandler [![Build Status](https://travis-ci.org/fb55/domhandler.svg?branch=master)](https://travis-ci.org/fb55/domhandler)
2
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.
4
5 ## Usage
6 ```javascript
7 var handler = new DomHandler([ <func> callback(err, dom), ] [ <obj> options ]);
8 // var parser = new Parser(handler[, options]);
9 ```
10
11 Available options are described below.
12
13 ## Example
14 ```javascript
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) {
18     if (error)
19         [...do something for errors...]
20     else
21         [...parsing done, do something...]
22         console.log(dom);
23 });
24 var parser = new htmlparser.Parser(handler);
25 parser.write(rawHtml);
26 parser.end();
27 ```
28
29 Output:
30
31 ```javascript
32 [{
33     data: 'Xyz ',
34     type: 'text'
35 }, {
36     type: 'script',
37     name: 'script',
38     attribs: {
39         language: 'javascript'
40     },
41     children: [{
42         data: 'var foo = \'<bar>\';<',
43         type: 'text'
44     }]
45 }, {
46     data: '<!-- Waah! -- ',
47     type: 'comment'
48 }]
49 ```
50
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". 
53
54 The following HTML will be used:
55
56 ```html
57 <font>
58         <br>this is the text
59 <font>
60 ```
61
62 ### Example: true
63
64 ```javascript
65 [{
66     type: 'tag',
67     name: 'font',
68     children: [{
69         data: ' ',
70         type: 'text'
71     }, {
72         type: 'tag',
73         name: 'br'
74     }, {
75         data: 'this is the text ',
76         type: 'text'
77     }, {
78         type: 'tag',
79         name: 'font'
80     }]
81 }]
82 ```
83
84 ### Example: false
85
86 ```javascript
87 [{
88     type: 'tag',
89     name: 'font',
90     children: [{
91         data: '\n\t',
92         type: 'text'
93     }, {
94         type: 'tag',
95         name: 'br'
96     }, {
97         data: 'this is the text\n',
98         type: 'text'
99     }, {
100         type: 'tag',
101         name: 'font'
102     }]
103 }]
104 ```
105
106 ## Option: withDomLvl1
107
108 Adds DOM level 1 properties to all elements.
109
110 <!-- TODO: description -->
111
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".
114
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".