0.4.6 • Published 6 years ago

htmlparser2-es6 v0.4.6

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

htmlparser2-es6

A minimalist ES6-compatible HTML/XML parser. A callback interface is provided.

Installation

npm install htmlparser2-es6

A live demo of the original htmlparser2 is available here.

Usage

var htmlparser = require("htmlparser2-es6");
var parser = new htmlparser({
	onopentag: function(name, attribs){
		if(name === "script" && attribs.type === "text/javascript"){
			console.log("JS! Hooray!");
		}
	},
	ontext: function(text){
		console.log("-->", text);
	},
	onclosetag: function(tagname){
		if(tagname === "script"){
			console.log("That's it?!");
		}
	}
}, {decodeEntities: true});
parser.write("Xyz <script type='text/javascript'>var foo = '<<bar>>';</ script>");
parser.end();

Output (simplified):

--> Xyz
JS! Hooray!
--> var foo = '<<bar>>';
That's it?!

Documentation

Read more about the original htmlparser2 module and its options in the htmlparser2 wiki. Note that this module only provides the Parser interface.

Performance

After having some artificial benchmarks for some time, @AndreasMadsen published his htmlparser-benchmark, which benchmarks HTML parses based on real-world websites.

At the time of writing, the latest versions of all supported parsers show the following performance characteristics on Travis CI (please note that Travis doesn't guarantee equal conditions for all tests):

gumbo-parser   : 34.9208 ms/file ± 21.4238
html-parser    : 24.8224 ms/file ± 15.8703
html5          : 419.597 ms/file ± 264.265
htmlparser     : 60.0722 ms/file ± 384.844
htmlparser2-dom: 12.0749 ms/file ± 6.49474
htmlparser2    : 7.49130 ms/file ± 5.74368
hubbub         : 30.4980 ms/file ± 16.4682
libxmljs       : 14.1338 ms/file ± 18.6541
parse5         : 22.0439 ms/file ± 15.3743
sax            : 49.6513 ms/file ± 26.6032
0.4.6

6 years ago

0.4.5

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.92

7 years ago