From a4e644c2857b015c53e1b459f95d9782f94fea12 Mon Sep 17 00:00:00 2001 From: Noor Christensen Date: Thu, 20 Jul 2017 16:21:47 +0200 Subject: [PATCH] Add support for breadability module in readability userscript --- misc/userscripts/readability | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/misc/userscripts/readability b/misc/userscripts/readability index 65b160695..639e3a111 100755 --- a/misc/userscripts/readability +++ b/misc/userscripts/readability @@ -12,15 +12,22 @@ # from __future__ import absolute_import import codecs, os -from readability.readability import Document tmpfile=os.path.expanduser('~/.local/share/qutebrowser/userscripts/readability.html') if not os.path.exists(os.path.dirname(tmpfile)): os.makedirs(os.path.dirname(tmpfile)) with codecs.open(os.environ['QUTE_HTML'], 'r', 'utf-8') as source: - doc = Document(source.read()) - content = doc.summary().replace('', '%s' % doc.title()) + data = source.read() + + try: + from breadability.readable import Article as reader + doc = reader(data) + content = doc.readable + except ImportError: + from readability import Document + doc = Document(data) + content = doc.summary().replace('', '%s' % doc.title()) with codecs.open(tmpfile, 'w', 'utf-8') as target: target.write('')