summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2016-04-01 07:42:40 +0200
committerFlorian Bruhin <git@the-compiler.org>2016-04-01 07:42:40 +0200
commite3a8d00f2789a7e5b05f04c8543902bf381c05c7 (patch)
tree37f9ad967fd7b149651cc836292f4c3d5e0dc244
parent6631c6456cae10ddd10c06125a0a4a7818349019 (diff)
downloadqutebrowser-e3a8d00f2789a7e5b05f04c8543902bf381c05c7.tar.gz
qutebrowser-e3a8d00f2789a7e5b05f04c8543902bf381c05c7.zip
Include cheatsheet images in offline help
Fixes #329. Note the png's are kind of outdated right now.
-rw-r--r--doc/img/cheatsheet-big.pngbin0 -> 965071 bytes
-rw-r--r--doc/img/cheatsheet-small.pngbin0 -> 44342 bytes
-rw-r--r--qutebrowser/browser/network/qutescheme.py5
-rwxr-xr-xscripts/asciidoc2html.py34
4 files changed, 37 insertions, 2 deletions
diff --git a/doc/img/cheatsheet-big.png b/doc/img/cheatsheet-big.png
new file mode 100644
index 000000000..b18a0519c
--- /dev/null
+++ b/doc/img/cheatsheet-big.png
Binary files differ
diff --git a/doc/img/cheatsheet-small.png b/doc/img/cheatsheet-small.png
new file mode 100644
index 000000000..af11e9e40
--- /dev/null
+++ b/doc/img/cheatsheet-small.png
Binary files differ
diff --git a/qutebrowser/browser/network/qutescheme.py b/qutebrowser/browser/network/qutescheme.py
index 42a7dfb52..9daea70e4 100644
--- a/qutebrowser/browser/network/qutescheme.py
+++ b/qutebrowser/browser/network/qutescheme.py
@@ -210,7 +210,10 @@ def qute_help(win_id, request):
message.error(win_id, "Your documentation is outdated! Please re-run "
"scripts/asciidoc2html.py.")
path = 'html/doc/{}'.format(urlpath)
- return utils.read_file(path).encode('UTF-8', errors='xmlcharrefreplace')
+ if urlpath.endswith('.png'):
+ return utils.read_file(path, binary=True)
+ else:
+ return utils.read_file(path).encode('UTF-8', errors='xmlcharrefreplace')
@add_handler('settings')
diff --git a/scripts/asciidoc2html.py b/scripts/asciidoc2html.py
index d0a0b3537..b8f5d59e1 100755
--- a/scripts/asciidoc2html.py
+++ b/scripts/asciidoc2html.py
@@ -76,6 +76,7 @@ class AsciiDoc:
self._build_website()
else:
self._build_docs()
+ self._copy_images()
def _build_docs(self):
"""Render .asciidoc files to .html sites."""
@@ -84,8 +85,39 @@ class AsciiDoc:
name, _ext = os.path.splitext(os.path.basename(src))
dst = 'qutebrowser/html/doc/{}.html'.format(name)
files.append((src, dst))
+
+ # patch image links to use local copy
+ modified_files = []
+ replacements = [
+ ("http://qutebrowser.org/img/cheatsheet-big.png",
+ "qute://help/img/cheatsheet-big.png"),
+ ("http://qutebrowser.org/img/cheatsheet-small.png",
+ "qute://help/img/cheatsheet-small.png")
+ ]
+
for src, dst in files:
- self.call(src, dst)
+ src_basename = os.path.basename(src)
+ modified_src = os.path.join(self._tempdir, src_basename)
+ with open(modified_src, 'w', encoding='utf-8') as modified_f, \
+ open(src, 'r', encoding='utf-8') as f:
+ for line in f:
+ for orig, repl in replacements:
+ line = line.replace(orig, repl)
+ modified_f.write(line)
+ self.call(modified_src, dst)
+
+ def _copy_images(self):
+ """Copy image files to qutebrowser/html/doc."""
+ print("Copying files...")
+ dst_path = os.path.join('qutebrowser', 'html', 'doc', 'img')
+ try:
+ os.mkdir(dst_path)
+ except FileExistsError:
+ pass
+ for filename in ['cheatsheet-big.png', 'cheatsheet-small.png']:
+ src = os.path.join('doc', 'img', filename)
+ dst = os.path.join(dst_path, filename)
+ shutil.copy(src, dst)
def _build_website_file(self, root, filename):
"""Build a single website file."""