GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
peek() is required for streaming parsers.
In browsers, the live DOM (document.*) must be updated with new output from the HTML parser in these situations (and possibly others):
1 Done reading HTML from a single packet
2 script tag found
3 document.write() call completed
So we need a way to query the parser's DOM state without calling done(), which prevents any further parsing.
This gist shows how peek() would be used in a simple case:
This is a more complex use case where we sync the DOM whenever a script tag appears:
Now supports peek() method, which calls the handler callback without …
…terminating the parse.
Thanks for the contribution! Looking through it now and will get back to you with questions or just accept the pull.
Sweet! By the way, this is a little unclear from those gist examples: calling peek() will trigger the handler callback function with the partial DOM, so seeing that callback no longer implies that parsing is totally finished.
FYI - Working on 1.8 now and working through pull requests