Add support for breadability module in readability userscript
This commit is contained in:
parent
57167a5cde
commit
a4e644c285
@ -12,15 +12,22 @@
|
|||||||
#
|
#
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import codecs, os
|
import codecs, os
|
||||||
from readability.readability import Document
|
|
||||||
|
|
||||||
tmpfile=os.path.expanduser('~/.local/share/qutebrowser/userscripts/readability.html')
|
tmpfile=os.path.expanduser('~/.local/share/qutebrowser/userscripts/readability.html')
|
||||||
if not os.path.exists(os.path.dirname(tmpfile)):
|
if not os.path.exists(os.path.dirname(tmpfile)):
|
||||||
os.makedirs(os.path.dirname(tmpfile))
|
os.makedirs(os.path.dirname(tmpfile))
|
||||||
|
|
||||||
with codecs.open(os.environ['QUTE_HTML'], 'r', 'utf-8') as source:
|
with codecs.open(os.environ['QUTE_HTML'], 'r', 'utf-8') as source:
|
||||||
doc = Document(source.read())
|
data = source.read()
|
||||||
content = doc.summary().replace('<html>', '<html><head><title>%s</title></head>' % doc.title())
|
|
||||||
|
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('<html>', '<html><head><title>%s</title></head>' % doc.title())
|
||||||
|
|
||||||
with codecs.open(tmpfile, 'w', 'utf-8') as target:
|
with codecs.open(tmpfile, 'w', 'utf-8') as target:
|
||||||
target.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />')
|
target.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />')
|
||||||
|
Loading…
Reference in New Issue
Block a user