Mozilla Readability in GNU Emacs
Output using Readability (left) and original eww (right) |
Mozilla Readability is a standalone version of the readability library used for Firefox Reader View. A simple hack to eww can bring the same feature in GNU Emacs. (Note: eww already has a readable mode. This is just an alternative. Updated the post to reflect the same.)
- Install NodeJS
- Install npm modules.
npm install @mozilla/readability jsdom
- Create a file readability.js with following content. Note the file location.
var { Readability } = require('@mozilla/readability');
var { JSDOM } = require('jsdom');
var fs = require("fs");
var str = fs.readFileSync(process.stdin.fd).toString();
var doc = new JSDOM(str);
var reader = new Readability(doc.window.document);
var article = reader.parse();
console.log(article.content);
var { JSDOM } = require('jsdom');
var fs = require("fs");
var str = fs.readFileSync(process.stdin.fd).toString();
var doc = new JSDOM(str);
var reader = new Readability(doc.window.document);
var article = reader.parse();
console.log(article.content);
- Modify the following function to use the file location noted above. Evaluate the function.
(defun mozilla-readability (start end)
(shell-command-on-region start end "node <full path to readability.js>" nil t))
(shell-command-on-region start end "node <full path to readability.js>" nil t))
- Modify eww.el to use the function by adding the line below.
@@ -765,6 +768,7 @@ eww-readable
(condition-case nil
(decode-coding-region (point-min) (point-max) 'utf-8)
(coding-system-error nil))
+ (mozilla-readability (point-min) (point-max))
(eww--preprocess-html (point-min) (point-max))
(libxml-parse-html-region (point-min) (point-max))))
(base (plist-get eww-data :url)))
(condition-case nil
(decode-coding-region (point-min) (point-max) 'utf-8)
(coding-system-error nil))
+ (mozilla-readability (point-min) (point-max))
(eww--preprocess-html (point-min) (point-max))
(libxml-parse-html-region (point-min) (point-max))))
(base (plist-get eww-data :url)))
- Use M-x eww as you would normally do. Use R (eww-readable) to view the Firefox readable version.
Comments
Post a Comment