Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. <p align="center">
  2. <img src="https://raw.github.com/inikulin/parse5/master/docs/logo.png" alt="parse5" />
  3. </p>
  4. <p align="center">
  5. <a href="https://www.npmjs.com/package/parse5"><img alt="NPM Version" src="https://img.shields.io/npm/v/parse5.svg"></a>
  6. </p>
  7. <p align="center">
  8. <i>WHATWG HTML5 specification-compliant, fast and ready for production HTML parsing/serialization toolset for Node.</i>
  9. </p>
  10. <b><i>parse5</i></b> contains nearly everything what you will need to deal with the HTML. It's the fastest spec-compliant HTML parser
  11. for Node to the date and will parse HTML the way the latest version of your browser does. It's stable and used
  12. by such projects as [jsdom](https://github.com/tmpvar/jsdom), [Angular2](https://github.com/angular/angular),
  13. [Polymer](https://www.polymer-project.org/1.0/) and many more.
  14. # Table of contents
  15. * [Install](#install)
  16. * [Usage](#usage)
  17. * [API Reference](#api-reference)
  18. * [FAQ](#faq)
  19. * [Version history](#version-history)
  20. * [License](#license-and-author-information)
  21. # Install
  22. ```
  23. $ npm install parse5
  24. ```
  25. # Usage
  26. ```js
  27. var parse5 = require('parse5');
  28. var document = parse5.parse('<!DOCTYPE html><html><body>Hi there!</body></html>');
  29. var documentHtml = parse5.serialize(document);
  30. var fragment = parse5.parseFragment('<td>Yo!</td>');
  31. var fragmentHtml = parse5.serialize(fragment);
  32. ```
  33. For more advanced examples see [API reference](#api-reference) and [FAQ](#faq).
  34. # API Reference
  35. ## Objects
  36. <dl>
  37. <dt><a href="#parse5">parse5</a> : <code>object</code></dt>
  38. <dd></dd>
  39. </dl>
  40. ## Typedefs
  41. <dl>
  42. <dt><a href="#ElementLocationInfo">ElementLocationInfo</a> : <code>Object</code></dt>
  43. <dd></dd>
  44. <dt><a href="#LocationInfo">LocationInfo</a> : <code>Object</code></dt>
  45. <dd></dd>
  46. <dt><a href="#ParserOptions">ParserOptions</a> : <code>Object</code></dt>
  47. <dd></dd>
  48. <dt><a href="#SAXParserOptions">SAXParserOptions</a> : <code>Object</code></dt>
  49. <dd></dd>
  50. <dt><a href="#SerializerOptions">SerializerOptions</a> : <code>Object</code></dt>
  51. <dd></dd>
  52. <dt><a href="#TreeAdapter">TreeAdapter</a> : <code>Object</code></dt>
  53. <dd></dd>
  54. </dl>
  55. <a name="parse5"></a>
  56. ## parse5 : <code>object</code>
  57. **Kind**: global namespace
  58. * [parse5](#parse5) : <code>object</code>
  59. * [.ParserStream](#parse5+ParserStream) ⇐ <code>stream.Writable</code>
  60. * [new ParserStream(options)](#new_parse5+ParserStream_new)
  61. * [.document](#parse5+ParserStream+document) : <code>ASTNode.&lt;document&gt;</code>
  62. * ["script" (scriptElement, documentWrite(html), resume)](#parse5+ParserStream+event_script)
  63. * [.SAXParser](#parse5+SAXParser) ⇐ <code>stream.Transform</code>
  64. * [new SAXParser(options)](#new_parse5+SAXParser_new)
  65. * [.stop()](#parse5+SAXParser+stop)
  66. * ["startTag" (name, attributes, selfClosing, [location])](#parse5+SAXParser+event_startTag)
  67. * ["endTag" (name, [location])](#parse5+SAXParser+event_endTag)
  68. * ["comment" (text, [location])](#parse5+SAXParser+event_comment)
  69. * ["doctype" (name, publicId, systemId, [location])](#parse5+SAXParser+event_doctype)
  70. * ["text" (text, [location])](#parse5+SAXParser+event_text)
  71. * [.SerializerStream](#parse5+SerializerStream) ⇐ <code>stream.Readable</code>
  72. * [new SerializerStream(node, [options])](#new_parse5+SerializerStream_new)
  73. * [.treeAdapters](#parse5+treeAdapters)
  74. * [.parse(html, [options])](#parse5+parse) ⇒ <code>ASTNode.&lt;Document&gt;</code>
  75. * [.parseFragment([fragmentContext], html, [options])](#parse5+parseFragment) ⇒ <code>ASTNode.&lt;DocumentFragment&gt;</code>
  76. * [.serialize(node, [options])](#parse5+serialize) ⇒ <code>String</code>
  77. <a name="parse5+ParserStream"></a>
  78. ### parse5.ParserStream ⇐ <code>stream.Writable</code>
  79. **Kind**: instance class of <code>[parse5](#parse5)</code>
  80. **Extends:** <code>stream.Writable</code>
  81. * [.ParserStream](#parse5+ParserStream) ⇐ <code>stream.Writable</code>
  82. * [new ParserStream(options)](#new_parse5+ParserStream_new)
  83. * [.document](#parse5+ParserStream+document) : <code>ASTNode.&lt;document&gt;</code>
  84. * ["script" (scriptElement, documentWrite(html), resume)](#parse5+ParserStream+event_script)
  85. <a name="new_parse5+ParserStream_new"></a>
  86. #### new ParserStream(options)
  87. Streaming HTML parser with the scripting support.
  88. [Writable stream](https://nodejs.org/api/stream.html#stream_class_stream_writable).
  89. | Param | Type | Description |
  90. | --- | --- | --- |
  91. | options | <code>[ParserOptions](#ParserOptions)</code> | Parsing options. |
  92. **Example**
  93. ```js
  94. var parse5 = require('parse5');
  95. var http = require('http');
  96. // Fetch google.com content and obtain it's <body> node
  97. http.get('http://google.com', function(res) {
  98. var parser = new parse5.ParserStream();
  99. parser.on('finish', function() {
  100. var body = parser.document.childNodes[0].childNodes[1];
  101. });
  102. res.pipe(parser);
  103. });
  104. ```
  105. <a name="parse5+ParserStream+document"></a>
  106. #### parserStream.document : <code>ASTNode.&lt;document&gt;</code>
  107. Resulting document node.
  108. **Kind**: instance property of <code>[ParserStream](#parse5+ParserStream)</code>
  109. <a name="parse5+ParserStream+event_script"></a>
  110. #### "script" (scriptElement, documentWrite(html), resume)
  111. Raised then parser encounters `<script>` element.
  112. If event has listeners then parsing will be suspended on event emission.
  113. So, if `<script>` has `src` attribute you can fetch it, execute and then
  114. resume parser like browsers do.
  115. **Kind**: event emitted by <code>[ParserStream](#parse5+ParserStream)</code>
  116. | Param | Type | Description |
  117. | --- | --- | --- |
  118. | scriptElement | <code>ASTNode</code> | Script element that caused the event. |
  119. | documentWrite(html) | <code>function</code> | Write additional `html` at the current parsing position. Suitable for the DOM `document.write` and `document.writeln` methods implementation. |
  120. | resume | <code>function</code> | Resumes the parser. |
  121. **Example**
  122. ```js
  123. var parse = require('parse5');
  124. var http = require('http');
  125. var parser = new parse5.ParserStream();
  126. parser.on('script', function(scriptElement, documentWrite, resume) {
  127. var src = parse5.treeAdapters.default.getAttrList(scriptElement)[0].value;
  128. http.get(src, function(res) {
  129. // Fetch script content, execute it with DOM built around `parser.document` and
  130. // `document.write` implemented using `documentWrite`
  131. ...
  132. // Then resume the parser
  133. resume();
  134. });
  135. });
  136. parser.end('<script src="example.com/script.js"></script>');
  137. ```
  138. <a name="parse5+SAXParser"></a>
  139. ### parse5.SAXParser ⇐ <code>stream.Transform</code>
  140. **Kind**: instance class of <code>[parse5](#parse5)</code>
  141. **Extends:** <code>stream.Transform</code>
  142. * [.SAXParser](#parse5+SAXParser) ⇐ <code>stream.Transform</code>
  143. * [new SAXParser(options)](#new_parse5+SAXParser_new)
  144. * [.stop()](#parse5+SAXParser+stop)
  145. * ["startTag" (name, attributes, selfClosing, [location])](#parse5+SAXParser+event_startTag)
  146. * ["endTag" (name, [location])](#parse5+SAXParser+event_endTag)
  147. * ["comment" (text, [location])](#parse5+SAXParser+event_comment)
  148. * ["doctype" (name, publicId, systemId, [location])](#parse5+SAXParser+event_doctype)
  149. * ["text" (text, [location])](#parse5+SAXParser+event_text)
  150. <a name="new_parse5+SAXParser_new"></a>
  151. #### new SAXParser(options)
  152. Streaming [SAX](https://en.wikipedia.org/wiki/Simple_API_for_XML)-style HTML parser.
  153. [Transform stream](https://nodejs.org/api/stream.html#stream_class_stream_transform)
  154. (which means you can pipe *through* it, see example).
  155. | Param | Type | Description |
  156. | --- | --- | --- |
  157. | options | <code>[SAXParserOptions](#SAXParserOptions)</code> | Parsing options. |
  158. **Example**
  159. ```js
  160. var parse5 = require('parse5');
  161. var http = require('http');
  162. var fs = require('fs');
  163. var file = fs.createWriteStream('/home/google.com.html');
  164. var parser = new SAXParser();
  165. parser.on('text', function(text) {
  166. // Handle page text content
  167. ...
  168. });
  169. http.get('http://google.com', function(res) {
  170. // SAXParser is the Transform stream, which means you can pipe
  171. // through it. So you can analyze page content and e.g. save it
  172. // to the file at the same time:
  173. res.pipe(parser).pipe(file);
  174. });
  175. ```
  176. <a name="parse5+SAXParser+stop"></a>
  177. #### saxParser.stop()
  178. Stops parsing. Useful if you want parser to stop consume
  179. CPU time once you've obtained desired info from input stream.
  180. Doesn't prevents piping, so data will flow through parser as usual.
  181. **Kind**: instance method of <code>[SAXParser](#parse5+SAXParser)</code>
  182. **Example**
  183. ```js
  184. var parse5 = require('parse5');
  185. var http = require('http');
  186. var fs = require('fs');
  187. var file = fs.createWriteStream('/home/google.com.html');
  188. var parser = new parse5.SAXParser();
  189. parser.on('doctype', function(name, publicId, systemId) {
  190. // Process doctype info ans stop parsing
  191. ...
  192. parser.stop();
  193. });
  194. http.get('http://google.com', function(res) {
  195. // Despite the fact that parser.stop() was called whole
  196. // content of the page will be written to the file
  197. res.pipe(parser).pipe(file);
  198. });
  199. ```
  200. <a name="parse5+SAXParser+event_startTag"></a>
  201. #### "startTag" (name, attributes, selfClosing, [location])
  202. Raised then parser encounters start tag.
  203. **Kind**: event emitted by <code>[SAXParser](#parse5+SAXParser)</code>
  204. | Param | Type | Description |
  205. | --- | --- | --- |
  206. | name | <code>String</code> | Tag name. |
  207. | attributes | <code>String</code> | List of attributes in `{ key: String, value: String }` form. |
  208. | selfClosing | <code>Boolean</code> | Indicates if tag is self-closing. |
  209. | [location] | <code>[LocationInfo](#LocationInfo)</code> | Start tag source code location info. Available if location info is enabled in [SAXParserOptions](#SAXParserOptions). |
  210. <a name="parse5+SAXParser+event_endTag"></a>
  211. #### "endTag" (name, [location])
  212. Raised then parser encounters end tag.
  213. **Kind**: event emitted by <code>[SAXParser](#parse5+SAXParser)</code>
  214. | Param | Type | Description |
  215. | --- | --- | --- |
  216. | name | <code>String</code> | Tag name. |
  217. | [location] | <code>[LocationInfo](#LocationInfo)</code> | End tag source code location info. Available if location info is enabled in [SAXParserOptions](#SAXParserOptions). |
  218. <a name="parse5+SAXParser+event_comment"></a>
  219. #### "comment" (text, [location])
  220. Raised then parser encounters comment.
  221. **Kind**: event emitted by <code>[SAXParser](#parse5+SAXParser)</code>
  222. | Param | Type | Description |
  223. | --- | --- | --- |
  224. | text | <code>String</code> | Comment text. |
  225. | [location] | <code>[LocationInfo](#LocationInfo)</code> | Comment source code location info. Available if location info is enabled in [SAXParserOptions](#SAXParserOptions). |
  226. <a name="parse5+SAXParser+event_doctype"></a>
  227. #### "doctype" (name, publicId, systemId, [location])
  228. Raised then parser encounters [document type declaration](https://en.wikipedia.org/wiki/Document_type_declaration).
  229. **Kind**: event emitted by <code>[SAXParser](#parse5+SAXParser)</code>
  230. | Param | Type | Description |
  231. | --- | --- | --- |
  232. | name | <code>String</code> | Document type name. |
  233. | publicId | <code>String</code> | Document type public identifier. |
  234. | systemId | <code>String</code> | Document type system identifier. |
  235. | [location] | <code>[LocationInfo](#LocationInfo)</code> | Document type declaration source code location info. Available if location info is enabled in [SAXParserOptions](#SAXParserOptions). |
  236. <a name="parse5+SAXParser+event_text"></a>
  237. #### "text" (text, [location])
  238. Raised then parser encounters text content.
  239. **Kind**: event emitted by <code>[SAXParser](#parse5+SAXParser)</code>
  240. | Param | Type | Description |
  241. | --- | --- | --- |
  242. | text | <code>String</code> | Text content. |
  243. | [location] | <code>[LocationInfo](#LocationInfo)</code> | Text content code location info. Available if location info is enabled in [SAXParserOptions](#SAXParserOptions). |
  244. <a name="parse5+SerializerStream"></a>
  245. ### parse5.SerializerStream ⇐ <code>stream.Readable</code>
  246. **Kind**: instance class of <code>[parse5](#parse5)</code>
  247. **Extends:** <code>stream.Readable</code>
  248. <a name="new_parse5+SerializerStream_new"></a>
  249. #### new SerializerStream(node, [options])
  250. Streaming AST node to HTML serializer.
  251. [Readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable).
  252. | Param | Type | Description |
  253. | --- | --- | --- |
  254. | node | <code>ASTNode</code> | Node to serialize. |
  255. | [options] | <code>[SerializerOptions](#SerializerOptions)</code> | Serialization options. |
  256. **Example**
  257. ```js
  258. var parse5 = require('parse5');
  259. var fs = require('fs');
  260. var file = fs.createWriteStream('/home/index.html');
  261. // Serialize parsed document to the HTML and write it to file
  262. var document = parse5.parse('<body>Who is John Galt?</body>');
  263. var serializer = new parse5.SerializerStream(document);
  264. serializer.pipe(file);
  265. ```
  266. <a name="parse5+treeAdapters"></a>
  267. ### parse5.treeAdapters
  268. Provides built-in tree adapters which can be used for parsing and serialization.
  269. **Kind**: instance property of <code>[parse5](#parse5)</code>
  270. **Properties**
  271. | Name | Type | Description |
  272. | --- | --- | --- |
  273. | default | <code>[TreeAdapter](#TreeAdapter)</code> | Default tree format for parse5. |
  274. | htmlparser2 | <code>[TreeAdapter](#TreeAdapter)</code> | Quite popular [htmlparser2](https://github.com/fb55/htmlparser2) tree format (e.g. used by [cheerio](https://github.com/MatthewMueller/cheerio) and [jsdom](https://github.com/tmpvar/jsdom)). |
  275. **Example**
  276. ```js
  277. var parse5 = require('parse5');
  278. // Use default tree adapter for parsing
  279. var document = parse5.parse('<div></div>', { treeAdapter: parse5.treeAdapters.default });
  280. // Use htmlparser2 tree adapter with SerializerStream
  281. var serializer = new parse5.SerializerStream(node, { treeAdapter: parse5.treeAdapters.htmlparser2 });
  282. ```
  283. <a name="parse5+parse"></a>
  284. ### parse5.parse(html, [options]) ⇒ <code>ASTNode.&lt;Document&gt;</code>
  285. Parses HTML string.
  286. **Kind**: instance method of <code>[parse5](#parse5)</code>
  287. **Returns**: <code>ASTNode.&lt;Document&gt;</code> - document
  288. | Param | Type | Description |
  289. | --- | --- | --- |
  290. | html | <code>string</code> | Input HTML string. |
  291. | [options] | <code>[ParserOptions](#ParserOptions)</code> | Parsing options. |
  292. **Example**
  293. ```js
  294. var parse5 = require('parse5');
  295. var document = parse5.parse('<!DOCTYPE html><html><head></head><body>Hi there!</body></html>');
  296. ```
  297. <a name="parse5+parseFragment"></a>
  298. ### parse5.parseFragment([fragmentContext], html, [options]) ⇒ <code>ASTNode.&lt;DocumentFragment&gt;</code>
  299. Parses HTML fragment.
  300. **Kind**: instance method of <code>[parse5](#parse5)</code>
  301. **Returns**: <code>ASTNode.&lt;DocumentFragment&gt;</code> - documentFragment
  302. | Param | Type | Description |
  303. | --- | --- | --- |
  304. | [fragmentContext] | <code>ASTNode</code> | Parsing context element. If specified, given fragment will be parsed as if it was set to the context element's `innerHTML` property. |
  305. | html | <code>string</code> | Input HTML fragment string. |
  306. | [options] | <code>[ParserOptions](#ParserOptions)</code> | Parsing options. |
  307. **Example**
  308. ```js
  309. var parse5 = require('parse5');
  310. var documentFragment = parse5.parseFragment('<table></table>');
  311. //Parse html fragment in context of the parsed <table> element
  312. var trFragment = parser.parseFragment(documentFragment.childNodes[0], '<tr><td>Shake it, baby</td></tr>');
  313. ```
  314. <a name="parse5+serialize"></a>
  315. ### parse5.serialize(node, [options]) ⇒ <code>String</code>
  316. Serializes AST node to HTML string.
  317. **Kind**: instance method of <code>[parse5](#parse5)</code>
  318. **Returns**: <code>String</code> - html
  319. | Param | Type | Description |
  320. | --- | --- | --- |
  321. | node | <code>ASTNode</code> | Node to serialize. |
  322. | [options] | <code>[SerializerOptions](#SerializerOptions)</code> | Serialization options. |
  323. **Example**
  324. ```js
  325. var parse5 = require('parse5');
  326. var document = parse5.parse('<!DOCTYPE html><html><head></head><body>Hi there!</body></html>');
  327. //Serialize document
  328. var html = parse5.serialize(document);
  329. //Serialize <body> element content
  330. var bodyInnerHtml = parse5.serialize(document.childNodes[0].childNodes[1]);
  331. ```
  332. <a name="ElementLocationInfo"></a>
  333. ## ElementLocationInfo : <code>Object</code>
  334. **Kind**: global typedef
  335. **Extends:** <code>[LocationInfo](#LocationInfo)</code>
  336. **Properties**
  337. | Name | Type | Description |
  338. | --- | --- | --- |
  339. | startTag | <code>[LocationInfo](#LocationInfo)</code> | Element's start tag [LocationInfo](#LocationInfo). |
  340. | endTag | <code>[LocationInfo](#LocationInfo)</code> | Element's end tag [LocationInfo](#LocationInfo). |
  341. <a name="LocationInfo"></a>
  342. ## LocationInfo : <code>Object</code>
  343. **Kind**: global typedef
  344. **Properties**
  345. | Name | Type | Description |
  346. | --- | --- | --- |
  347. | line | <code>Number</code> | One-based line index |
  348. | col | <code>Number</code> | One-based column index |
  349. | startOffset | <code>Number</code> | Zero-based first character index |
  350. | endOffset | <code>Number</code> | Zero-based last character index |
  351. <a name="ParserOptions"></a>
  352. ## ParserOptions : <code>Object</code>
  353. **Kind**: global typedef
  354. **Properties**
  355. | Name | Type | Default | Description |
  356. | --- | --- | --- | --- |
  357. | locationInfo | <code>Boolean</code> | <code>false</code> | Enables source code location information for the nodes. When enabled, each node (except root node) has `__location` property. In case the node is not an empty element, `__location` will be [ElementLocationInfo](#ElementLocationInfo) object, otherwise it's [LocationInfo](#LocationInfo). If element was implicitly created by the parser it's `__location` property will be `null`. |
  358. | treeAdapter | <code>[TreeAdapter](#TreeAdapter)</code> | <code>parse5.treeAdapters.default</code> | Specifies resulting tree format. |
  359. <a name="SAXParserOptions"></a>
  360. ## SAXParserOptions : <code>Object</code>
  361. **Kind**: global typedef
  362. **Properties**
  363. | Name | Type | Default | Description |
  364. | --- | --- | --- | --- |
  365. | locationInfo | <code>Boolean</code> | <code>false</code> | Enables source code location information for the tokens. When enabled, each token event handler will receive [LocationInfo](#LocationInfo) object as the last argument. |
  366. <a name="SerializerOptions"></a>
  367. ## SerializerOptions : <code>Object</code>
  368. **Kind**: global typedef
  369. **Properties**
  370. | Name | Type | Default | Description |
  371. | --- | --- | --- | --- |
  372. | treeAdapter | <code>[TreeAdapter](#TreeAdapter)</code> | <code>parse5.treeAdapters.default</code> | Specifies input tree format. |
  373. <a name="TreeAdapter"></a>
  374. ## TreeAdapter : <code>Object</code>
  375. **Kind**: global typedef
  376. * [TreeAdapter](#TreeAdapter) : <code>Object</code>
  377. * [.createDocument()](#TreeAdapter.createDocument) ⇒ <code>ASTNode.&lt;Document&gt;</code>
  378. * [.createDocumentFragment()](#TreeAdapter.createDocumentFragment) ⇒ <code>ASTNode.&lt;DocumentFragment&gt;</code>
  379. * [.createElement(tagName, namespaceURI, attrs)](#TreeAdapter.createElement) ⇒ <code>ASTNode.&lt;Element&gt;</code>
  380. * [.createElement(data)](#TreeAdapter.createElement) ⇒ <code>ASTNode.&lt;CommentNode&gt;</code>
  381. * [.setDocumentType(document, name, publicId, systemId)](#TreeAdapter.setDocumentType)
  382. * [.setQuirksMode(document)](#TreeAdapter.setQuirksMode)
  383. * [.setQuirksMode(document)](#TreeAdapter.setQuirksMode) ⇒ <code>Boolean</code>
  384. * [.detachNode(node)](#TreeAdapter.detachNode)
  385. * [.insertText(parentNode, text)](#TreeAdapter.insertText)
  386. * [.insertTextBefore(parentNode, text, referenceNode)](#TreeAdapter.insertTextBefore)
  387. * [.adoptAttributes(recipientNode, attrs)](#TreeAdapter.adoptAttributes)
  388. * [.getFirstChild(node)](#TreeAdapter.getFirstChild) ⇒ <code>ASTNode</code>
  389. * [.getChildNodes(node)](#TreeAdapter.getChildNodes) ⇒ <code>Array</code>
  390. * [.getParentNode(node)](#TreeAdapter.getParentNode) ⇒ <code>ASTNode</code>
  391. * [.getAttrList(node)](#TreeAdapter.getAttrList) ⇒ <code>Array</code>
  392. * [.getTagName(element)](#TreeAdapter.getTagName) ⇒ <code>String</code>
  393. * [.getNamespaceURI(element)](#TreeAdapter.getNamespaceURI) ⇒ <code>String</code>
  394. * [.getTextNodeContent(textNode)](#TreeAdapter.getTextNodeContent) ⇒ <code>String</code>
  395. * [.getTextNodeContent(commentNode)](#TreeAdapter.getTextNodeContent) ⇒ <code>String</code>
  396. * [.getDocumentTypeNodeName(doctypeNode)](#TreeAdapter.getDocumentTypeNodeName) ⇒ <code>String</code>
  397. * [.getDocumentTypeNodePublicId(doctypeNode)](#TreeAdapter.getDocumentTypeNodePublicId) ⇒ <code>String</code>
  398. * [.getDocumentTypeNodeSystemId(doctypeNode)](#TreeAdapter.getDocumentTypeNodeSystemId) ⇒ <code>String</code>
  399. * [.isTextNode(node)](#TreeAdapter.isTextNode) ⇒ <code>Boolean</code>
  400. * [.isCommentNode(node)](#TreeAdapter.isCommentNode) ⇒ <code>Boolean</code>
  401. * [.isDocumentTypeNode(node)](#TreeAdapter.isDocumentTypeNode) ⇒ <code>Boolean</code>
  402. * [.isElementNode(node)](#TreeAdapter.isElementNode) ⇒ <code>Boolean</code>
  403. <a name="TreeAdapter.createDocument"></a>
  404. ### TreeAdapter.createDocument() ⇒ <code>ASTNode.&lt;Document&gt;</code>
  405. Creates document node
  406. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  407. **Returns**: <code>ASTNode.&lt;Document&gt;</code> - document
  408. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L19)
  409. <a name="TreeAdapter.createDocumentFragment"></a>
  410. ### TreeAdapter.createDocumentFragment() ⇒ <code>ASTNode.&lt;DocumentFragment&gt;</code>
  411. Creates document fragment node
  412. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  413. **Returns**: <code>ASTNode.&lt;DocumentFragment&gt;</code> - fragment
  414. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L37)
  415. <a name="TreeAdapter.createElement"></a>
  416. ### TreeAdapter.createElement(tagName, namespaceURI, attrs) ⇒ <code>ASTNode.&lt;Element&gt;</code>
  417. Creates element node
  418. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  419. **Returns**: <code>ASTNode.&lt;Element&gt;</code> - element
  420. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L61)
  421. | Param | Type | Description |
  422. | --- | --- | --- |
  423. | tagName | <code>String</code> | Tag name of the element. |
  424. | namespaceURI | <code>String</code> | Namespace of the element. |
  425. | attrs | <code>Array</code> | Attribute name-value pair array. Foreign attributes may contain `namespace` and `prefix` fields as well. |
  426. <a name="TreeAdapter.createElement"></a>
  427. ### TreeAdapter.createElement(data) ⇒ <code>ASTNode.&lt;CommentNode&gt;</code>
  428. Creates comment node
  429. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  430. **Returns**: <code>ASTNode.&lt;CommentNode&gt;</code> - comment
  431. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L85)
  432. | Param | Type | Description |
  433. | --- | --- | --- |
  434. | data | <code>String</code> | Comment text. |
  435. <a name="TreeAdapter.setDocumentType"></a>
  436. ### TreeAdapter.setDocumentType(document, name, publicId, systemId)
  437. Sets document type. If `document` already have document type node in it then
  438. `name`, `publicId` and `systemId` properties of the node will be updated with
  439. the provided values. Otherwise, creates new document type node with the given
  440. properties and inserts it into `document`.
  441. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  442. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L131)
  443. | Param | Type | Description |
  444. | --- | --- | --- |
  445. | document | <code>ASTNode.&lt;Document&gt;</code> | Document node. |
  446. | name | <code>String</code> | Document type name. |
  447. | publicId | <code>String</code> | Document type public identifier. |
  448. | systemId | <code>String</code> | Document type system identifier. |
  449. <a name="TreeAdapter.setQuirksMode"></a>
  450. ### TreeAdapter.setQuirksMode(document)
  451. Sets document quirks mode flag.
  452. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  453. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L167)
  454. | Param | Type | Description |
  455. | --- | --- | --- |
  456. | document | <code>ASTNode.&lt;Document&gt;</code> | Document node. |
  457. <a name="TreeAdapter.setQuirksMode"></a>
  458. ### TreeAdapter.setQuirksMode(document) ⇒ <code>Boolean</code>
  459. Determines if document quirks mode flag is set.
  460. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  461. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L183)
  462. | Param | Type | Description |
  463. | --- | --- | --- |
  464. | document | <code>ASTNode.&lt;Document&gt;</code> | Document node. |
  465. <a name="TreeAdapter.detachNode"></a>
  466. ### TreeAdapter.detachNode(node)
  467. Removes node from it's parent.
  468. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  469. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L197)
  470. | Param | Type | Description |
  471. | --- | --- | --- |
  472. | node | <code>ASTNode</code> | Node. |
  473. <a name="TreeAdapter.insertText"></a>
  474. ### TreeAdapter.insertText(parentNode, text)
  475. Inserts text into node. If the last child of the node is the text node then
  476. provided text will be appended to the text node content. Otherwise, inserts
  477. new text node with the given text.
  478. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  479. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L220)
  480. | Param | Type | Description |
  481. | --- | --- | --- |
  482. | parentNode | <code>ASTNode</code> | Node to insert text into. |
  483. | text | <code>String</code> | Text to insert. |
  484. <a name="TreeAdapter.insertTextBefore"></a>
  485. ### TreeAdapter.insertTextBefore(parentNode, text, referenceNode)
  486. Inserts text into node before the referenced child node. If node before the
  487. referenced child node is the text node then provided text will be appended
  488. to the text node content. Otherwise, inserts new text node with the given text
  489. before the referenced child node.
  490. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  491. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L249)
  492. | Param | Type | Description |
  493. | --- | --- | --- |
  494. | parentNode | <code>ASTNode</code> | Node to insert text into. |
  495. | text | <code>String</code> | Text to insert. |
  496. | referenceNode | <code>ASTNode</code> | Node to insert text before. |
  497. <a name="TreeAdapter.adoptAttributes"></a>
  498. ### TreeAdapter.adoptAttributes(recipientNode, attrs)
  499. Copies attributes to the given node. Only those nodes
  500. which are not yet present in the node are copied.
  501. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  502. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L270)
  503. | Param | Type | Description |
  504. | --- | --- | --- |
  505. | recipientNode | <code>ASTNode</code> | Node to copy attributes into. |
  506. | attrs | <code>Array</code> | Attributes to copy. |
  507. <a name="TreeAdapter.getFirstChild"></a>
  508. ### TreeAdapter.getFirstChild(node) ⇒ <code>ASTNode</code>
  509. Returns first child of the given node.
  510. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  511. **Returns**: <code>ASTNode</code> - firstChild
  512. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L297)
  513. | Param | Type | Description |
  514. | --- | --- | --- |
  515. | node | <code>ASTNode</code> | Node. |
  516. <a name="TreeAdapter.getChildNodes"></a>
  517. ### TreeAdapter.getChildNodes(node) ⇒ <code>Array</code>
  518. Returns array of the given node's children.
  519. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  520. **Returns**: <code>Array</code> - children
  521. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L313)
  522. | Param | Type | Description |
  523. | --- | --- | --- |
  524. | node | <code>ASTNode</code> | Node. |
  525. <a name="TreeAdapter.getParentNode"></a>
  526. ### TreeAdapter.getParentNode(node) ⇒ <code>ASTNode</code>
  527. Returns given node's parent.
  528. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  529. **Returns**: <code>ASTNode</code> - parent
  530. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L329)
  531. | Param | Type | Description |
  532. | --- | --- | --- |
  533. | node | <code>ASTNode</code> | Node. |
  534. <a name="TreeAdapter.getAttrList"></a>
  535. ### TreeAdapter.getAttrList(node) ⇒ <code>Array</code>
  536. Returns array of the given node's attributes in form of the name-value pair.
  537. Foreign attributes may contain `namespace` and `prefix` fields as well.
  538. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  539. **Returns**: <code>Array</code> - attributes
  540. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L346)
  541. | Param | Type | Description |
  542. | --- | --- | --- |
  543. | node | <code>ASTNode</code> | Node. |
  544. <a name="TreeAdapter.getTagName"></a>
  545. ### TreeAdapter.getTagName(element) ⇒ <code>String</code>
  546. Returns given element's tag name.
  547. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  548. **Returns**: <code>String</code> - tagName
  549. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L364)
  550. | Param | Type | Description |
  551. | --- | --- | --- |
  552. | element | <code>ASTNode.&lt;Element&gt;</code> | Element. |
  553. <a name="TreeAdapter.getNamespaceURI"></a>
  554. ### TreeAdapter.getNamespaceURI(element) ⇒ <code>String</code>
  555. Returns given element's namespace.
  556. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  557. **Returns**: <code>String</code> - namespaceURI
  558. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L380)
  559. | Param | Type | Description |
  560. | --- | --- | --- |
  561. | element | <code>ASTNode.&lt;Element&gt;</code> | Element. |
  562. <a name="TreeAdapter.getTextNodeContent"></a>
  563. ### TreeAdapter.getTextNodeContent(textNode) ⇒ <code>String</code>
  564. Returns given text node's content.
  565. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  566. **Returns**: <code>String</code> - text
  567. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L396)
  568. | Param | Type | Description |
  569. | --- | --- | --- |
  570. | textNode | <code>ASTNode.&lt;Text&gt;</code> | Text node. |
  571. <a name="TreeAdapter.getTextNodeContent"></a>
  572. ### TreeAdapter.getTextNodeContent(commentNode) ⇒ <code>String</code>
  573. Returns given comment node's content.
  574. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  575. **Returns**: <code>String</code> - commentText
  576. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L412)
  577. | Param | Type | Description |
  578. | --- | --- | --- |
  579. | commentNode | <code>ASTNode.&lt;Comment&gt;</code> | Comment node. |
  580. <a name="TreeAdapter.getDocumentTypeNodeName"></a>
  581. ### TreeAdapter.getDocumentTypeNodeName(doctypeNode) ⇒ <code>String</code>
  582. Returns given document type node's name.
  583. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  584. **Returns**: <code>String</code> - name
  585. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L428)
  586. | Param | Type | Description |
  587. | --- | --- | --- |
  588. | doctypeNode | <code>ASTNode.&lt;DocumentType&gt;</code> | Document type node. |
  589. <a name="TreeAdapter.getDocumentTypeNodePublicId"></a>
  590. ### TreeAdapter.getDocumentTypeNodePublicId(doctypeNode) ⇒ <code>String</code>
  591. Returns given document type node's public identifier.
  592. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  593. **Returns**: <code>String</code> - publicId
  594. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L444)
  595. | Param | Type | Description |
  596. | --- | --- | --- |
  597. | doctypeNode | <code>ASTNode.&lt;DocumentType&gt;</code> | Document type node. |
  598. <a name="TreeAdapter.getDocumentTypeNodeSystemId"></a>
  599. ### TreeAdapter.getDocumentTypeNodeSystemId(doctypeNode) ⇒ <code>String</code>
  600. Returns given document type node's system identifier.
  601. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  602. **Returns**: <code>String</code> - systemId
  603. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L460)
  604. | Param | Type | Description |
  605. | --- | --- | --- |
  606. | doctypeNode | <code>ASTNode.&lt;DocumentType&gt;</code> | Document type node. |
  607. <a name="TreeAdapter.isTextNode"></a>
  608. ### TreeAdapter.isTextNode(node) ⇒ <code>Boolean</code>
  609. Determines if given node is a text node.
  610. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  611. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L477)
  612. | Param | Type | Description |
  613. | --- | --- | --- |
  614. | node | <code>ASTNode</code> | Node. |
  615. <a name="TreeAdapter.isCommentNode"></a>
  616. ### TreeAdapter.isCommentNode(node) ⇒ <code>Boolean</code>
  617. Determines if given node is a comment node.
  618. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  619. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L493)
  620. | Param | Type | Description |
  621. | --- | --- | --- |
  622. | node | <code>ASTNode</code> | Node. |
  623. <a name="TreeAdapter.isDocumentTypeNode"></a>
  624. ### TreeAdapter.isDocumentTypeNode(node) ⇒ <code>Boolean</code>
  625. Determines if given node is a document type node.
  626. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  627. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L509)
  628. | Param | Type | Description |
  629. | --- | --- | --- |
  630. | node | <code>ASTNode</code> | Node. |
  631. <a name="TreeAdapter.isElementNode"></a>
  632. ### TreeAdapter.isElementNode(node) ⇒ <code>Boolean</code>
  633. Determines if given node is an element.
  634. **Kind**: static method of <code>[TreeAdapter](#TreeAdapter)</code>
  635. **See**: [default implementation.](https://github.com/inikulin/parse5/blob/tree-adapter-docs-rev/lib/tree_adapters/default.js#L525)
  636. | Param | Type | Description |
  637. | --- | --- | --- |
  638. | node | <code>ASTNode</code> | Node. |
  639. # FAQ
  640. ## Q: I want to work with my own document tree format. How can I achieve this?
  641. You can create a custom tree adapter so parse5 can work with your own DOM-tree implementation.
  642. Then just pass it to the parser or serializer via option:
  643. ```js
  644. var parse5 = require('parse5');
  645. var myTreeAdapter = {
  646. //Adapter methods...
  647. };
  648. var document = parse5.parse('<div></div>', { treeAdapter: myTreeAdapter });
  649. var html = parse5.serialize(document, { treeAdapter: myTreeAdapter });
  650. ```
  651. You can find description of the methods which should be exposed by tree adapter and links to their
  652. default implementation in the [API reference](#TreeAdapter).
  653. ## Q: How can I use parse5 in the browser?
  654. Just compile it with [browserify](http://browserify.org/) and you're set.
  655. ## Q: I'm parsing `<img src="foo">` with the `SAXParser` and I expect `selfClosing` flag to be `true` for the `<img>` tag. But it's not. Is there something wrong with parser?
  656. No. Self-closing tag is the tag that has `/` before the closing bracket. E.g: `<br/>`, `<meta/>`.
  657. In the provided example tag just doesn't have end tag. Self-closing tags and tags without end tags are differently treated by the
  658. parser: in case of self-closing tag parser will not lookup for the appropriate closing tag and expects element to not have any content.
  659. But if start tag is not self-closing parser will treat everything after it (with the few exceptions) as the element content.
  660. However, if the start tag is in the list of [void elements](https://html.spec.whatwg.org/multipage/syntax.html#void-elements) parser expects corresponding
  661. element to not have content and behaves the same way as the if element is self-closing. So, semantically if element is the
  662. void element self-closing tags and tags without closing tags are equivalent, but it's not true for all other tags.
  663. **TL;DR**: `selfClosing` is the part of the lexical information and will be set only if the tag in source code has `/` before the closing bracket.
  664. ## Q: I have some weird output from the parser, seems like it's a bug.
  665. More likely, it's not. There are a lot of weird edge cases in HTML5 parsing algorithm, e.g.:
  666. ```html
  667. <b>1<p>2</b>3</p>
  668. ```
  669. will be parsed as
  670. ```html
  671. <b>1</b><p><b>2</b>3</p>
  672. ```
  673. Just try it in the latest version of your browser before submitting the issue.
  674. # Version history
  675. ## 2.0.0
  676. * Add: [ParserStream](http://inikulin.github.io/parse5/#parse5+ParserStream) with the scripting support.
  677. * Add: [SerializerStream](http://inikulin.github.io/parse5/#parse5+SerializerStream)
  678. * Add: Line/column location info.
  679. * Update (**breaking**): `SimpleApiParser` was renamed to [SAXParser](http://inikulin.github.io/parse5/#parse5+SAXParser).
  680. * Update (**breaking**): [SAXParser](http://inikulin.github.io/parse5/#parse5+SAXParser) is the [transform stream](https://nodejs.org/api/stream.html#stream_class_stream_transform)
  681. now.
  682. * Update (**breaking**): [SAXParser](http://inikulin.github.io/parse5/#parse5+SAXParser) handler subscription is done via events now.
  683. * Add: [SAXParser.stop()](http://inikulin.github.io/parse5/#parse5+SAXParser+stop)
  684. * Add (**breaking**): [parse5.parse()](http://inikulin.github.io/parse5/#parse5+parse) and [parse5.parseFragment()](http://inikulin.github.io/parse5/#parse5+parseFragment)
  685. methods as replacement for the `Parser` class.
  686. * Add (**breaking**): [parse5.serialize()](http://inikulin.github.io/parse5/#parse5+serialized) method as replacement for the `Serializer` class.
  687. * Update: parsing algorithm was updated with the latest [HTML spec](https://html.spec.whatwg.org/) changes.
  688. * Remove (**breaking**): `decodeHtmlEntities` and `encodeHtmlEntities` options. [Discussion](https://github.com/inikulin/parse5/issues/75).
  689. ## 1.5.0
  690. * Add: Location info for the element start and end tags (by @sakagg).
  691. ## 1.4.2
  692. * Fix: htmlparser2 tree adapter `DocumentType.data` property rendering (GH [#45](https://github.com/inikulin/parse5/issues/45)).
  693. ## 1.4.1
  694. * Fix: Location info handling for the implicitly generated `<html>` and `<body>` elements (GH [#44](https://github.com/inikulin/parse5/issues/44)).
  695. ## 1.4.0
  696. * Add: Parser [decodeHtmlEntities](https://github.com/inikulin/parse5#optionsdecodehtmlentities) option.
  697. * Add: SimpleApiParser [decodeHtmlEntities](https://github.com/inikulin/parse5#optionsdecodehtmlentities-1) option.
  698. * Add: Parser [locationInfo](https://github.com/inikulin/parse5#optionslocationinfo) option.
  699. * Add: SimpleApiParser [locationInfo](https://github.com/inikulin/parse5#optionslocationinfo-1) option.
  700. ## 1.3.2
  701. * Fix: `<form>` processing in `<template>` (GH [#40](https://github.com/inikulin/parse5/issues/40)).
  702. ## 1.3.1
  703. * Fix: text node in `<template>` serialization problem with custom tree adapter (GH [#38](https://github.com/inikulin/parse5/issues/38)).
  704. ## 1.3.0
  705. * Add: Serializer `encodeHtmlEntities` option.
  706. ## 1.2.0
  707. * Add: `<template>` support
  708. * `parseFragment` now uses `<template>` as default `contextElement`. This leads to the more "forgiving" parsing manner.
  709. * `TreeSerializer` was renamed to `Serializer`. However, serializer is accessible as `parse5.TreeSerializer` for backward compatibility .
  710. ## 1.1.6
  711. * Fix: apply latest changes to the `htmlparser2` tree format (DOM Level1 node emulation).
  712. ## 1.1.5
  713. * Add: [jsdom](https://github.com/tmpvar/jsdom)-specific parser with scripting support. Undocumented for `jsdom` internal use only.
  714. ## 1.1.4
  715. * Add: logo
  716. * Fix: use fake `document` element for fragment parsing (required by [jsdom](https://github.com/tmpvar/jsdom)).
  717. ## 1.1.3
  718. * Development files (e.g. `.travis.yml`, `.editorconfig`) are removed from NPM package.
  719. ## 1.1.2
  720. * Fix: crash on Linux due to upper-case leading character in module name used in `require()`.
  721. ## 1.1.1
  722. * Add: [SimpleApiParser](https://github.com/inikulin/parse5/#class-simpleapiparser).
  723. * Fix: new line serialization in `<pre>`.
  724. * Fix: `SYSTEM`-only `DOCTYPE` serialization.
  725. * Fix: quotes serialization in `DOCTYPE` IDs.
  726. ## 1.0.0
  727. * First stable release, switch to semantic versioning.
  728. ## 0.8.3
  729. * Fix: siblings calculation bug in `appendChild` in `htmlparser2` tree adapter.
  730. ## 0.8.1
  731. * Add: [TreeSerializer](https://github.com/inikulin/parse5/#class-serializer).
  732. * Add: [htmlparser2 tree adapter](https://github.com/inikulin/parse5/#-treeadaptershtmlparser2).
  733. ## 0.6.1
  734. * Fix: incorrect `<menuitem>` handling in `<body>`.
  735. ## 0.6.0
  736. * Initial release.
  737. # License
  738. Copyright (c) 2013-2015 Ivan Nikulin (ifaaan@gmail.com, https://github.com/inikulin)
  739. Permission is hereby granted, free of charge, to any person obtaining a copy
  740. of this software and associated documentation files (the "Software"), to deal
  741. in the Software without restriction, including without limitation the rights
  742. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  743. copies of the Software, and to permit persons to whom the Software is
  744. furnished to do so, subject to the following conditions:
  745. The above copyright notice and this permission notice shall be included in
  746. all copies or substantial portions of the Software.
  747. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  748. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  749. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  750. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  751. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  752. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  753. THE SOFTWARE.