Skip to content

Instantly share code, notes, and snippets.

@davidar
Created November 10, 2016 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidar/e21a46f5aea8d4a52a223d44b6e7a660 to your computer and use it in GitHub Desktop.
Save davidar/e21a46f5aea8d4a52a223d44b6e7a660 to your computer and use it in GitHub Desktop.
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