Skip to content

Instantly share code, notes, and snippets.

@Valid
Created October 21, 2010 06:11
Show Gist options
  • Save Valid/638045 to your computer and use it in GitHub Desktop.
Save Valid/638045 to your computer and use it in GitHub Desktop.
require.paths.unshift('lib')
require.paths.unshift('deps/jsdom/lib')
var HTML5 = require('html5'),
Script = process.binding('evals').Script,
sys = require('sys'),
fs = require('fs'),
jsdom = require('jsdom'),
http = require('http'),
window = jsdom.createWindow(null, null, {
parser: HTML5,
document: new jsdom.dom.level1.core.Document()
}),
uriToParse = 'www.google.com',
site = http.createClient(80, uriToParse);
request = site.request('GET', '/', {
'host': uriToParse
});
request.end();
window.document.removeChild(window.document.childNodes[0]); // Clear the stub document that jsdom gives us
var parser = new HTML5.Parser({
document: window.document
});
request.on('response', function (response) {
var data = '';
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
response.setEncoding('utf8');
response.on('data', function (chunk) {
//console.log('BODY: ' + chunk);
data += chunk;
});
response.on('end', function (chunk) {
console.log(typeof data);
//var inputfile = fs.readFileSync('doc/jquery-example.html');
//inputfile = "<div><p>This is a test</p></div>"
//parser.parse(inputfile);
parser.parse(data);
jsdom.jQueryify(window, 'deps/jquery/dist/jquery.js', function (window, jquery) {
Script.runInNewContext('jQuery("span").append("<b>Hi!</b>")', window);
sys.puts(window.document.innerHTML);
});
});
});
@Valid
Copy link
Author

Valid commented Oct 21, 2010

lib/html5/tokenizer.js:62
throw(e);
^
TypeError: Object #<an Object> has no method 'createDocumentType'
at TreeBuilder.insert_doctype (lib/html5/treebuilder.js:92:45)
at Object.processDoctype (lib/html5/parser/initial_phase.js:26:12)
at EventEmitter.do_token (lib/html5/parser.js:100:20)
at EventEmitter.<anonymous> (lib/html5/parser.js:112:30)
at EventEmitter.emit (events:27:15)
at EventEmitter.emitToken (lib/html5/tokenizer.js:84:7)
at EventEmitter.emit_current_token (lib/html5/tokenizer.js:813:7)
at EventEmitter.doctype_name_state (lib/html5/tokenizer.js:756:8)
at EventEmitter.<anonymous> (lib/html5/tokenizer.js:59:25)
at EventEmitter.emit (events:27:15)

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