Skip to content

nerdlabs/fast-html

Repository files navigation

fast-html Build Status Coverage Status

fast-html is a sax-style HTML parser focused on performance. It only copes with sane HTML - see the Things that break section.

Install

npm install --save fast-html

Docs

Test-documentation generated with mocha's "doc" reporter.

Usage

var fastHtml = require('fast-html')({ parseAttributes: true });

// Receive start tags
fastHtml.on('start', function(tagName, attributes){

});

// Receive text nodes
fastHtml.on('data', function(text){

});

// Receive end tags
fastHtml.on('end', function(tagName)) {

});

// Release the hounds
fastHtml.parse('<ul id="list"><li>Hello World</li></ul>')

Things that break

FastHTML is designed for maximum performance, therefore it will not

  • Try to fix broken markup
  • Try to fix slightly broken markup
  • Try to do automagic closing stuff
  • Be graceful about unescaped HTML strings in inline script, style and HTML attributes

Solutions

  • </script> strings in inline script - Use <![CDATA[...]]>.
  • HTML strings in attributes - Escape them.