inikulin/parse5
Description: parse5 - Fast full-featured HTML parser for Node. Based on WHATWG HTML5 specification.

This repository
This repository
All repositories

- Explore
- Gist
- Blog
- Help

- inikulin

- New repository
- New organization
- This repository
- New issue
- New collaborator

- 22 Unwatch
  Notification status

  #### Not watching

  You only receive notifications for conversations in which you participate or are @mentioned. Watch

  #### Watching

  You receive notifications for all conversations in this repository. Unwatch

  #### Ignoring

  You do not receive any notifications for conversations in this repository. Stop ignoring
- Unstar Star 406
- Fork 14

# public inikulin / parse5

- Code
- Issues 0
- Pull Requests 0
- Wiki

- Pulse
- Graphs
- Network

- Settings

### HTTPS clone URL

### SSH clone URL

### Subversion checkout URL

You can clone with HTTPS, SSH, or Subversion.

Clone in Desktop Download ZIP

Fast full-featured HTML parser for Node. Based on WHATWG HTML5 specification.

Description
Website
or cancel

- 149 commits
- 1 branch
- 2 releases
- 2 contributors

1. JavaScript 100%

JavaScript
branch: master
Switch branches/tags

- Branches
- Tags

master

#### Create branch:

from ‘master’
v0.6.0
0.6.1
Nothing to show
parse5 /
Show File Finder

htmlparser2 tree adapter tested

latest commit 3397219353
inikulin authored January 27, 2014

| lib | htmlparser2 tree adapter tested | January 27, 2014
| test | htmlparser2 tree adapter tested | January 27, 2014
| .gitignore | Merge | July 15, 2013
| LICENSE | Merge | July 15, 2013
| README.md | Add a Bitdeli badge to README | December 10, 2013
| index.js | Implementation of the htmlparser2 tree support started | January 24, 2014
| package.json | Expose Tokenizer | January 24, 2014

README.md

# parse5

Fast full-featured HTML parser for Node. Based on WHATWG HTML5 specification.
To build TestCafé we needed fast and ready for production HTML parser for node.js, which will parse HTML as a modern browser's parser. Existing solutions were either too slow or their output was too inaccurate. So, this is how parse5 was born.

## Install

    $ npm install parse5

## Usage and API

    var Parser = require('parse5').Parser;

    //Instantiate parser
    var parser = new Parser();

    //Then feed it with an HTML document
    var document = parser.parse('<!DOCTYPE html><html><head></head><body>Hi there!</body></html>')

    //Now let's parse HTML-snippet
    var fragment = parser.parseFragment('<title>Parse5 is &#102;&#117;&#99;&#107;ing awesome!</title><h1>42</h1>');

## Is it fast?

Check out this benchmark.

    Starting benchmark. Fasten your seatbelts...
    html5 (https://github.com/aredridel/html5) x 0.18 ops/sec ±5.92% (5 runs sampled)
    htmlparser (https://github.com/tautologistics/node-htmlparser/) x 3.83 ops/sec ±42.43% (14 runs sampled)
    htmlparser2 (https://github.com/fb55/htmlparser2) x 4.05 ops/sec ±39.27% (15 runs sampled)
    parse5 (https://github.com/inikulin/parse5) x 3.04 ops/sec ±51.81% (13 runs sampled)
    Fastest is htmlparser2 (https://github.com/fb55/htmlparser2),parse5 (https://github.com/inikulin/parse5)

So, parse5 is as fast as simple specification incompatible parsers and ~15-times(!) faster than the current specification compatible parser available for the node.

## Testing

Test data is adopted from html5lib project. Parser is covered by more than 8000 test cases. To run tests:

    $ node test/run_tests.js

## Custom tree adapter

You can create a custom tree adapter so parse5 can work with your own DOM-tree implementation. Just pass your adapter implementation to the parser's constructor as an argument:

    var Parser = require('parse5').Parser;

    var myTreeAdapter = {
    //Adapter methods...
    };

    //Instantiate parser
    var parser = new Parser(myTreeAdapter);

Sample implementation can be found here. The custom tree adapter should implement all methods exposed via `exports` in the sample implementation.

## Questions or suggestions?

If you have any questions, please feel free to create an issue here on github.

## Author

Ivan Nikulin (ifaaan@gmail.com)

- Status
- API
- Training
- Shop
- Blog
- About

- © 2014 GitHub, Inc.
- Terms
- Privacy
- Security
- Contact

Something went wrong with that request. Please try again.