diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index 02aac14ad..cec8215fc 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -349,6 +349,23 @@ def qute_gpl(_url): return 'text/html', utils.read_file('html/license.html') +def _asciidoc_fallback_path(path): + """Fall back to plaintext asciidoc if the HTML is unavailable.""" + asciidoc_path = path.replace('.html', '.asciidoc') + asciidoc_paths = [asciidoc_path] + if asciidoc_path.startswith('html/doc/'): + asciidoc_paths += [asciidoc_path.replace('html/doc/', '../doc/help/'), + asciidoc_path.replace('html/doc/', '../doc/')] + + for path in asciidoc_paths: + try: + return utils.read_file(path) + except OSError: + pass + + return None + + @add_handler('help') def qute_help(url): """Handler for qute://help.""" @@ -373,22 +390,7 @@ def qute_help(url): try: data = utils.read_file(path) except OSError: - # No .html around, let's see if we find the asciidoc - asciidoc_path = path.replace('.html', '.asciidoc') - asciidoc_paths = [asciidoc_path] - if asciidoc_path.startswith('html/doc/'): - asciidoc_paths += [asciidoc_path.replace('html/doc/', '../doc/help/'), - asciidoc_path.replace('html/doc/', '../doc/')] - - asciidoc = None - - for path in asciidoc_paths: - try: - asciidoc = utils.read_file(path) - except OSError: - pass - else: - break + asciidoc = _asciidoc_fallback_path(path) if asciidoc is None: raise