{"_id":"stricter-htmlparser2","_rev":"3670553","name":"stricter-htmlparser2","description":"Fast & forgiving HTML/XML/RSS parser with stricter attribute parsing rules.","dist-tags":{"latest":"3.9.6"},"maintainers":[{"name":"yanghuabei","email":""}],"time":{"modified":"2025-02-13T05:41:00.000Z","created":"2018-08-17T05:11:59.471Z","3.9.6":"2018-08-20T02:59:40.054Z","3.9.5":"2018-08-20T02:23:24.214Z","3.9.4":"2018-08-19T12:50:37.247Z","3.9.3":"2018-08-17T05:11:59.471Z"},"users":{},"author":{"name":"Felix Boehm","email":"me@feedic.com"},"repository":{"type":"git","url":"git+ssh://git@github.com/yanghuabei/htmlparser2.git"},"versions":{"3.9.6":{"name":"stricter-htmlparser2","description":"Fast & forgiving HTML/XML/RSS parser with stricter attribute parsing rules.","version":"3.9.6","author":{"name":"Felix Boehm","email":"me@feedic.com"},"keywords":["html","parser","streams","xml","dom","rss","feed","atom"],"repository":{"type":"git","url":"git+ssh://git@github.com/yanghuabei/htmlparser2.git"},"bugs":{"url":"http://github.com/yanghuabei/htmlparser2/issues"},"directories":{"lib":"lib"},"main":"lib/index.js","files":["lib"],"scripts":{"lcov":"istanbul cover _mocha --report lcovonly -- -R spec","coveralls":"npm run lcov && (cat coverage/lcov.info | coveralls || exit 0)","test":"mocha","lint":"eslint lib"},"dependencies":{"domelementtype":"^1.3.0","domutils":"^1.5.1","entities":"^1.1.1","inherits":"^2.0.1","readable-stream":"^2.0.2","x-domhandler":"^2.4.2"},"devDependencies":{"coveralls":"^3.0.1","eslint":"^4.19.1","istanbul":"^0.4.3","mocha":"^5.2.0","mocha-lcov-reporter":"^1.2.0"},"browser":{"readable-stream":false},"license":"MIT","gitHead":"9b2cb0586f8a8d1f20efb8e3db65093b74ccf731","homepage":"https://github.com/yanghuabei/htmlparser2#readme","_id":"stricter-htmlparser2@3.9.6","_npmVersion":"6.2.0","_nodeVersion":"10.8.0","_npmUser":{"name":"yanghuabei","email":"yanghuabei@outlook.com"},"dist":{"shasum":"fd195f5e4bc0989c6b15fc79eca85c6401bb5045","size":12229,"noattachment":false,"key":"/stricter-htmlparser2/-/stricter-htmlparser2-3.9.6.tgz","tarball":"http://registry.cnpm.dingdandao.com/stricter-htmlparser2/download/stricter-htmlparser2-3.9.6.tgz"},"maintainers":[{"name":"yanghuabei","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/stricter-htmlparser2_3.9.6_1534733979973_0.19026241749856854"},"_hasShrinkwrap":false,"publish_time":1534733980054,"_cnpm_publish_time":1534733980054,"_cnpmcore_publish_time":"2021-12-17T10:43:25.657Z"},"3.9.5":{"name":"stricter-htmlparser2","description":"Fast & forgiving HTML/XML/RSS parser with stricter attribute parsing rules.","version":"3.9.5","author":{"name":"Felix Boehm","email":"me@feedic.com"},"keywords":["html","parser","streams","xml","dom","rss","feed","atom"],"repository":{"type":"git","url":"git+ssh://git@github.com/yanghuabei/htmlparser2.git"},"bugs":{"url":"http://github.com/yanghuabei/htmlparser2/issues"},"directories":{"lib":"lib"},"main":"lib/index.js","files":["lib"],"scripts":{"lcov":"istanbul cover _mocha --report lcovonly -- -R spec","coveralls":"npm run lcov && (cat coverage/lcov.info | coveralls || exit 0)","test":"mocha","lint":"eslint lib"},"dependencies":{"domelementtype":"^1.3.0","domutils":"^1.5.1","entities":"^1.1.1","inherits":"^2.0.1","readable-stream":"^2.0.2","x-domhandler":"^2.4.2"},"devDependencies":{"coveralls":"^3.0.1","eslint":"^4.19.1","istanbul":"^0.4.3","mocha":"^5.2.0","mocha-lcov-reporter":"^1.2.0"},"browser":{"readable-stream":false},"license":"MIT","gitHead":"845bd6b0deea74e9638dab9cb06587a4a7fbc19b","homepage":"https://github.com/yanghuabei/htmlparser2#readme","_id":"stricter-htmlparser2@3.9.5","_npmVersion":"6.2.0","_nodeVersion":"10.8.0","_npmUser":{"name":"yanghuabei","email":"yanghuabei@outlook.com"},"dist":{"shasum":"9c1395dc0097838244b34d1bb6eaedf8366e087c","size":12232,"noattachment":false,"key":"/stricter-htmlparser2/-/stricter-htmlparser2-3.9.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/stricter-htmlparser2/download/stricter-htmlparser2-3.9.5.tgz"},"maintainers":[{"name":"yanghuabei","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/stricter-htmlparser2_3.9.5_1534731804084_0.1583628456824775"},"_hasShrinkwrap":false,"publish_time":1534731804214,"_cnpm_publish_time":1534731804214,"_cnpmcore_publish_time":"2021-12-17T10:43:25.863Z"},"3.9.4":{"name":"stricter-htmlparser2","description":"Fast & forgiving HTML/XML/RSS parser with stricter attribute parsing rules.","version":"3.9.4","author":{"name":"Felix Boehm","email":"me@feedic.com"},"keywords":["html","parser","streams","xml","dom","rss","feed","atom"],"repository":{"type":"git","url":"git+ssh://git@github.com/yanghuabei/htmlparser2.git"},"bugs":{"url":"http://github.com/yanghuabei/htmlparser2/issues"},"directories":{"lib":"lib"},"main":"lib/index.js","files":["lib"],"scripts":{"lcov":"istanbul cover _mocha --report lcovonly -- -R spec","coveralls":"npm run lcov && (cat coverage/lcov.info | coveralls || exit 0)","test":"mocha","lint":"eslint lib"},"dependencies":{"domelementtype":"^1.3.0","domutils":"^1.5.1","entities":"^1.1.1","inherits":"^2.0.1","readable-stream":"^2.0.2","x-domhandler":"^2.4.2"},"devDependencies":{"coveralls":"^3.0.1","eslint":"^4.19.1","istanbul":"^0.4.3","mocha":"^5.2.0","mocha-lcov-reporter":"^1.2.0"},"browser":{"readable-stream":false},"license":"MIT","gitHead":"cbbf92d8f01da169f68c2e4fcba8e23b034713ff","homepage":"https://github.com/yanghuabei/htmlparser2#readme","_id":"stricter-htmlparser2@3.9.4","_npmVersion":"6.2.0","_nodeVersion":"10.8.0","_npmUser":{"name":"yanghuabei","email":"yanghuabei@outlook.com"},"dist":{"shasum":"8a4ca43e3528f6e2bf7350abbd3dcce516443e73","size":12166,"noattachment":false,"key":"/stricter-htmlparser2/-/stricter-htmlparser2-3.9.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/stricter-htmlparser2/download/stricter-htmlparser2-3.9.4.tgz"},"maintainers":[{"name":"yanghuabei","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/stricter-htmlparser2_3.9.4_1534683037188_0.10280308937342553"},"_hasShrinkwrap":false,"publish_time":1534683037247,"_cnpm_publish_time":1534683037247,"_cnpmcore_publish_time":"2021-12-17T10:43:26.057Z"},"3.9.3":{"name":"stricter-htmlparser2","description":"Fast & forgiving HTML/XML/RSS parser with stricter attribute parsing rules.","version":"3.9.3","author":{"name":"Felix Boehm","email":"me@feedic.com"},"keywords":["html","parser","streams","xml","dom","rss","feed","atom"],"repository":{"type":"git","url":"git+ssh://git@github.com/yanghuabei/htmlparser2.git"},"bugs":{"url":"http://github.com/yanghuabei/htmlparser2/issues"},"directories":{"lib":"lib"},"main":"lib/index.js","files":["lib"],"scripts":{"lcov":"istanbul cover _mocha --report lcovonly -- -R spec","coveralls":"npm run lint && npm run lcov && (cat coverage/lcov.info | coveralls || exit 0)","test":"mocha","lint":"eslint lib"},"dependencies":{"domelementtype":"^1.3.0","domhandler":"^2.3.0","domutils":"^1.5.1","entities":"^1.1.1","inherits":"^2.0.1","readable-stream":"^2.0.2"},"devDependencies":{"coveralls":"^3.0.1","eslint":"^4.19.1","istanbul":"^0.4.3","mocha":"^5.2.0","mocha-lcov-reporter":"^1.2.0"},"browser":{"readable-stream":false},"license":"MIT","gitHead":"ad93359fb1c24fe0844cfe7b4ced90fabaa2af4c","homepage":"https://github.com/yanghuabei/htmlparser2#readme","_id":"stricter-htmlparser2@3.9.3","_npmVersion":"6.2.0","_nodeVersion":"10.8.0","_npmUser":{"name":"yanghuabei","email":"yanghuabei@outlook.com"},"dist":{"shasum":"a0ae75703fe2bb4063f607232320d62c84cb8d62","size":11922,"noattachment":false,"key":"/stricter-htmlparser2/-/stricter-htmlparser2-3.9.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/stricter-htmlparser2/download/stricter-htmlparser2-3.9.3.tgz"},"maintainers":[{"name":"yanghuabei","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/stricter-htmlparser2_3.9.3_1534482719382_0.778961870445467"},"_hasShrinkwrap":false,"publish_time":1534482719471,"_cnpm_publish_time":1534482719471,"_cnpmcore_publish_time":"2021-12-17T10:43:26.350Z"}},"readme":"# stricter-htmlparser2\n\n[![NPM version](http://img.shields.io/npm/v/stricter-htmlparser2.svg?style=flat)](https://npmjs.org/package/stricter-htmlparser2)\n[![Downloads](https://img.shields.io/npm/dm/stricter-htmlparser2.svg?style=flat)](https://npmjs.org/package/stricter-htmlparser2)\n[![Build Status](http://img.shields.io/travis/yanghuabei/stricter-htmlparser2/master.svg?style=flat)](http://travis-ci.org/yanghuabei/htmlparser2)\n[![Coverage](http://img.shields.io/coveralls/yanghuabei/stricter-htmlparser2.svg?style=flat)](https://coveralls.io/r/yanghuabei/htmlparser2)\n\nA forgiving HTML/XML/RSS parser. The parser can handle streams and provides a callback interface.\n\n## Installation\n\tnpm install 'stricter-htmlparser2'\n\nA live demo of htmlparser2 is available [here](https://astexplorer.net/#/2AmVrGuGVJ).\n\n## Differences to htmlparser2\n1. Attribute value without quote wrapped is not allowed.\n\n\t```\n\t<foo name=value />\n\n\t// output\n\t{\n\t\tattribs: {\n\t\t\tname: \"\",\n\t\t\tvalue: \"\"\n\t\t}\n\t}\n\t```\n\n2. \"\\\"\" is allowed in attribute value.\n\n\t```\n\t<foo name=\"hello \\\"world\" />\n\n\t// output\n\t{\n\t\tattribs: {\n\t\t\tname: \"hello \\\\\"world\"\n\t\t}\n\t}\n\t```\n\n3. Record attributes key in a object that value is wrapped by single quote. The object is passed to `onopentag` method of parser's domhandler through the third argument.\n\n    ```\n\t<foo name='{{flag ? \"true\" : \"false\"}}' title=\"title\" class='hidden'> </foo>\n\n\t// The third argument passed to onopentag:\n\t{\n\t\tname: true,\n\t\tclass: true\n\t}\n\t```\n\n\t// If used with x-domhandler which is exported by this module, the parse result is like this:\n    ```javascript\n\t{\n\t\ttype: \"tag\",\n\t\tname: \"foo\",\n\t\tattribs: {\n\t\t\tname: \"{{flag ? \\\"true\\\" : \\\"false\\\"}}\",\n\t\t\ttitle: \"title\",\n\t\t\tclass: \"hidden\"\n\t\t},\n\t\tsingleQuoteAttribs: {\n\t\t\tname: true,\n\t\t\tclass: true\n\t\t},\n\t\tselfClose: false\n\t}\n\t```\n\n4. Add `selfClose` flag to parsed node element.\n\n\t**Input:**\n\n\t```html\n\t<foo name='{{flag ? \"true\" : \"false\"}}' title=\"title\" class='hidden' />\n\t```\n\n\t**Parser code:**\n\t```javascript\n\tconst {Parser, DomHandler} = require('stricter-htmlparser2');\n\n\tconst parser = new Parser(new DomHandler(), {}).end(inputStr);\n\t```\n\n\t**Output**\n\t```javascript\n\t{\n\t\ttype: \"tag\",\n\t\tname: \"foo\",\n\t\tattribs: {\n\t\t\tname: \"{{flag ? \\\"true\\\" : \\\"false\\\"}}\",\n\t\t\ttitle: \"title\",\n\t\t\tclass: \"hidden\"\n\t\t},\n\t\tsingleQuoteAttribs: {\n\t\t\tname: true,\n\t\t\tclass: true\n\t\t},\n\t\tselfClose: true\n\t}\n\t```\n\n## Usage\n\n```javascript\nvar htmlparser = require(\"stricter-htmlparser2\");\nvar parser = new htmlparser.Parser({\n\tonopentag: function(name, attribs){\n\t\tif(name === \"script\" && attribs.type === \"text/javascript\"){\n\t\t\tconsole.log(\"JS! Hooray!\");\n\t\t}\n\t},\n\tontext: function(text){\n\t\tconsole.log(\"-->\", text);\n\t},\n\tonclosetag: function(tagname){\n\t\tif(tagname === \"script\"){\n\t\t\tconsole.log(\"That's it?!\");\n\t\t}\n\t}\n}, {decodeEntities: true});\nparser.write(\"Xyz <script type='text/javascript'>var foo = '<<bar>>';</ script>\");\nparser.end();\n```\n\nOutput (simplified):\n\n```\n--> Xyz\nJS! Hooray!\n--> var foo = '<<bar>>';\nThat's it?!\n```\n\n## Documentation\n\nRead more about the parser and its options in the [wiki](https://github.com/fb55/htmlparser2/wiki/Parser-options).\n\n## Get a DOM\nThe `DomHandler` (known as `DefaultHandler` in the original `htmlparser` module) produces a DOM (document object model) that can be manipulated using the [`DomUtils`](https://github.com/fb55/DomUtils) helper.\n\nThe `DomHandler`, while still bundled with this module, was moved to its [own module](https://github.com/fb55/domhandler). Have a look at it for further information.\n\n## Parsing RSS/RDF/Atom Feeds\n\n```javascript\nnew htmlparser.FeedHandler(function(<error> error, <object> feed){\n    ...\n});\n```\n\nNote: While the provided feed handler works for most feeds, you might want to use  [danmactough/node-feedparser](https://github.com/danmactough/node-feedparser), which is much better tested and actively maintained.\n\n## Performance\n\nAfter having some artificial benchmarks for some time, __@AndreasMadsen__ published his [`htmlparser-benchmark`](https://github.com/AndreasMadsen/htmlparser-benchmark), which benchmarks HTML parses based on real-world websites.\n\nAt the time of writing, the latest versions of all supported parsers show the following performance characteristics on [Travis CI](https://travis-ci.org/AndreasMadsen/htmlparser-benchmark/builds/10805007) (please note that Travis doesn't guarantee equal conditions for all tests):\n\n```\ngumbo-parser   : 34.9208 ms/file ± 21.4238\nhtml-parser    : 24.8224 ms/file ± 15.8703\nhtml5          : 419.597 ms/file ± 264.265\nhtmlparser     : 60.0722 ms/file ± 384.844\nhtmlparser2-dom: 12.0749 ms/file ± 6.49474\nhtmlparser2    : 7.49130 ms/file ± 5.74368\nhubbub         : 30.4980 ms/file ± 16.4682\nlibxmljs       : 14.1338 ms/file ± 18.6541\nparse5         : 22.0439 ms/file ± 15.3743\nsax            : 49.6513 ms/file ± 26.6032\n```\n\n## How does this module differ from [node-htmlparser](https://github.com/tautologistics/node-htmlparser)?\n\nThis is a fork of the `htmlparser` module. The main difference is that this is intended to be used only with node (it runs on other platforms using [browserify](https://github.com/substack/node-browserify)). `htmlparser2` was rewritten multiple times and, while it maintains an API that's compatible with `htmlparser` in most cases, the projects don't share any code anymore.\n\nThe parser now provides a callback interface close to [sax.js](https://github.com/isaacs/sax-js) (originally targeted at [readabilitySAX](https://github.com/fb55/readabilitysax)). As a result, old handlers won't work anymore.\n\nThe `DefaultHandler` and the `RssHandler` were renamed to clarify their purpose (to `DomHandler` and `FeedHandler`). The old names are still available when requiring `htmlparser2`, your code should work as expected.\n","_attachments":{},"homepage":"https://github.com/yanghuabei/htmlparser2#readme","bugs":{"url":"http://github.com/yanghuabei/htmlparser2/issues"},"license":"MIT"}