Created
October 21, 2010 06:11
-
-
Save Valid/638045 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); | |
}); |
Author
Valid
commented
Oct 21, 2010
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment