Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

peek() method #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

peek() method #16

wants to merge 1 commit into from

Conversation

jtwb
Copy link

@jtwb jtwb commented Mar 1, 2011

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:
https://gist.github.com/849639/ec57b97213acb92b8a20e377d06cf1cffaf01e99

This is a more complex use case where we sync the DOM whenever a script tag appears:
https://gist.github.com/849639/dd05bcccefe82c0cc01d10c0ec54ce3f31bda4b8

@tautologistics
Copy link
Owner

Thanks for the contribution! Looking through it now and will get back to you with questions or just accept the pull.

@jtwb
Copy link
Author

jtwb commented Mar 4, 2011

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.

@tautologistics
Copy link
Owner

FYI - Working on 1.8 now and working through pull requests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants