Created
November 10, 2016 10:08
-
-
Save davidar/e21a46f5aea8d4a52a223d44b6e7a660 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
var jsdom = require("jsdom").jsdom; | |
var Readability = require("./index").Readability; | |
function removeCommentNodesRecursively(node) { | |
for (var i = node.childNodes.length - 1; i >= 0; i--) { | |
var child = node.childNodes[i]; | |
if (child.nodeType === child.COMMENT_NODE) { | |
node.removeChild(child); | |
} else if (child.nodeType === child.ELEMENT_NODE) { | |
removeCommentNodesRecursively(child); | |
} | |
} | |
} | |
jsdom.env(process.argv[2], [], function (err, window) { | |
if (err) { | |
console.error(err); | |
} else { | |
var document = window.document; | |
removeCommentNodesRecursively(document); | |
var loc = document.location; | |
var uri = { | |
spec: loc.href, | |
host: loc.host, | |
prePath: loc.protocol + "//" + loc.host, | |
scheme: loc.protocol.substr(0, loc.protocol.indexOf(":")), | |
pathBase: loc.protocol + "//" + loc.host + loc.pathname.substr(0, loc.pathname.lastIndexOf("/") + 1) | |
}; | |
console.log(new Readability(uri, document).parse()); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment