Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@ if(argv.h){
return;
}

var callback = function(err, article){
if(err)
var callback = function(err, article, meta){
if(err){
console.error(err);
process.stdout.write(article.html);
process.exit(-1);
}
if(!article.content){
process.exit(-2);
}
process.stdout.write(article.content);
}

if(typeof argv.url === 'string'){
read(argv.url, callback);
} else {
var html;
var html = "";
process.stdin.on("data", function(chunk){
html += chunk;
});
Expand Down
11 changes: 9 additions & 2 deletions src/readability.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Readability(window, options) {
};

this.__defineGetter__('content', function() {
return this.getContent(true);
return this.getContent(this, true);
});
this.__defineGetter__('title', function() {
return this.getTitle(true);
Expand All @@ -48,7 +48,7 @@ Readability.prototype.close = function() {
this._document = null;
};

Readability.prototype.getContent = function(notDeprecated) {
Readability.prototype.getContent = function(Readability, notDeprecated) {
if (!notDeprecated) {
console.warn('The method `getContent()` is deprecated, using `content` property instead.');
}
Expand All @@ -65,6 +65,13 @@ Readability.prototype.getContent = function(notDeprecated) {
}
}

// Add a h1 tag with the title when the articleContent doesn't contain a h1.
if(articleContent.getElementsByTagName("h1").length === 0){
var h1 = this._document.createElement("h1");
h1.innerHTML = Readability.title;
articleContent.insertBefore(h1, articleContent.childNodes[0]);
}

return this.cache['article-content'] = articleContent.innerHTML;
};

Expand Down