#!/usr/bin/env python3 # Creates a reader mode view of the current webpage # # Depends on the python-readability (lxml) package: # - http://github.com/buriy/python-readability # # Usage: # :spawn -u readability from __future__ import absolute_import import codecs, os tmpfile = "/tmp/readability.html" if not os.path.exists(os.path.dirname(tmpfile)): os.makedirs(os.path.dirname(tmpfile)) # Styling for dynamic window margin scaling and line height HEADER = """ %s """ with codecs.open(os.environ['QUTE_HTML'], 'r', 'utf-8') as source: data = source.read() from readability import Document doc = Document(data) title = doc.title() content = doc.summary().replace('', HEADER % title) with codecs.open(tmpfile, 'w', 'utf-8') as target: target.write(content.lstrip()) with open(os.environ['QUTE_FIFO'], 'w') as fifo: fifo.write('open -t %s' % tmpfile)