diff --git a/doc/img/cheatsheet-big.png b/doc/img/cheatsheet-big.png new file mode 100644 index 000000000..b18a0519c Binary files /dev/null and b/doc/img/cheatsheet-big.png differ diff --git a/doc/img/cheatsheet-small.png b/doc/img/cheatsheet-small.png new file mode 100644 index 000000000..af11e9e40 Binary files /dev/null and b/doc/img/cheatsheet-small.png 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."""