Skip to content

Instantly share code, notes, and snippets.

@jtwb
Created March 1, 2011 18:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtwb/849639 to your computer and use it in GitHub Desktop.
Save jtwb/849639 to your computer and use it in GitHub Desktop.
document.write
/*
* DJSParserSemantics.mixins.withParserDocwrite
*
* Parse HTML chunk, peek at the DOM and amend
* the live DOM with new nodes. Parsing must pause
* as soon as </script.*?> appears, so we force this
* by breaking the markup into chunks.
*/
var write = function(parser, out) {
var chunks = out.split(/<\/script[^>]*>/);
DJSUtil.forEach(chunks, function(chunk, index){
if (index < (chunks.length - 1)) {
chunk += "</script>";
} else if (chunk == "") {
return;
}
DJSUtil.log('Parsing document.write content: ' + chunk);
parser.parseChunk(chunk);
parser.peek();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment