FastHTML is a single-purpose HTML parser focused on performance. It only copes with sane HTML - see the Things that break section. Based upon node-fast-html-parser by ashi009
npm install --save fasthtml
Tests via htmlparser-benchmark are on the way.
Test-documentation generated with mocha's "doc" reporter.
var parse = require('fasthtml');
var root = parse('<ul id="list"><li>Hello World</li></ul>', createElementNode, createTextNode);
-
HTMLString
- HTMLstring
to parse -
elementNodeConstructor
-function
returning anElementNode
-
textNodeConstructor
-function
returning aTextNode
-
tagName
-string
tagName of theElementNode
-
attributes
-object
attribtues of theElementNode
-
textString
-string
contents of theTextNode
See createElementNode.js and createTextNode.js in ./test/lib/
var HTMLElement = function HTMLElement(name, attributes) {
this.tagName = name;
this.attributes = attributes;
this.childNodes = [];
if (attributes.id) {
this.id = attributes.id;
}
};
HTMLElement.prototype.appendChild = function (node) {
this.childNodes.push(node);
return node;
};
var TextNode = function TextNode(value) {
this.rawText = value;
}
function createElementNode(tagName, attributes) {
return new HTMLElement(tagName, attributes);
}
function createTextNode(textContent) {
return new TextNode(textContent);
}
var parse = require('fasthtml');
var parsed = parse('<ul id="list"><li>Hello World</li></ul>', createElementNode, createTextNode);
console.log(parsed);
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
Use <![CDATA[...]]>
.
Escape them.