high5
(eventually) spec-compliant html5 parser
Goals
My previous HTML parser, htmlparser2
, reached a point where a clean cut was needed. high5 is this cut, even though it's based on htmlparser2 and will try to be backwards compatible (I even tried to preserve the git history, so all previous committers are still credited).
Some of the things that will be supported:
- <input checked="" disabled="" type="checkbox">
doctype
s were treated as processing instructions & not parsed at all. - <input checked="" disabled="" type="checkbox"> Several token types that were previously handled as processing instruction tokens are handled as (bogus) comments in the HTML5 spec.
- <input disabled="" type="checkbox"> The
xmlMode
option will still be available & conditionally switch these features on. - <input disabled="" type="checkbox"> Add a document mode. (
htmlparser2
is always in fragment mode, meaning that eg. the empty document (""
) will result in an empty DOM.) - <input disabled="" type="checkbox"> Implicit opening & closing tags. (
htmlparser2
only checks the top element of the stack for the latter.) - <input disabled="" type="checkbox"> Foster parenting (eg.
<table><a>foo</a>…
should be handled as<a>foo</a><table>…
). - <input disabled="" type="checkbox"> (Potentially) handle character encodings (?).
State
- Spec-compliant* tokenizer
- Rudimentary tag-handling (still a long way to go, only marginally better than htmlparser2).
* The tokenizer takes several shortcuts, which greatly increase the speed of a JavaScript implementation, but disobay the spec implementation-wise. The output should be spec-compliant, though.