From be0d6ef3d253f8225d107a2f74b623aa84be317f Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 17 Sep 2018 09:51:15 +0200 Subject: [PATCH 1/2] Try more possible asciidoc paths for qute://help fallback --- doc/changelog.asciidoc | 2 ++ qutebrowser/browser/qutescheme.py | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index 0ec1d8003..2e346b00d 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -60,6 +60,8 @@ Fixed - Error when passing a substring with spaces to `:tab-take`. - Greasemonkey scripts which start with an UTF-8 BOM are now handled correctly. +- When no documentation has been generated, the plaintext documentation now can + be shown for more files such as `qute://help/userscripts.html`. Removed ~~~~~~~ diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index 5ff3f6fb0..02aac14ad 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -375,13 +375,20 @@ def qute_help(url): 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_path = asciidoc_path.replace('html/doc/', '../doc/help/') + asciidoc_paths += [asciidoc_path.replace('html/doc/', '../doc/help/'), + asciidoc_path.replace('html/doc/', '../doc/')] - try: - asciidoc = utils.read_file(asciidoc_path) - except OSError: - asciidoc = None + asciidoc = None + + for path in asciidoc_paths: + try: + asciidoc = utils.read_file(path) + except OSError: + pass + else: + break if asciidoc is None: raise From 27d0d148b853075c53bca55263309be80a317cb3 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 17 Sep 2018 10:29:00 +0200 Subject: [PATCH 2/2] Split up _asciidoc_fallback_path from qute_help --- qutebrowser/browser/qutescheme.py | 34 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 16 deletions(-) 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