chiark / gitweb /
documentation/python: allow relative links in top navbar.
authorVladimír Vondruš <mosra@centrum.cz>
Sat, 13 Jul 2019 15:52:33 +0000 (17:52 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Sun, 14 Jul 2019 17:11:08 +0000 (19:11 +0200)
For (local) Magnum Python docs I need to link to C++ docs, which are in
../../../bla/index.html.

documentation/python.py

index b62e13155a37c161ef20ef6847e8b009f2e65cf9..a56de157d29a608d847e76e1287bde9ba9ea9aa5 100755 (executable)
@@ -1365,11 +1365,13 @@ def run(basedir, config, templates):
         if urllib.parse.urlparse(path).netloc: return path
         return os.path.basename(path)
     # Filter to return URL for given symbol. If the path is a string, first try
-    # to treat it as an URL. If that fails, turn it into a list and try to look
-    # it up in various dicts.
+    # to treat it as an URL -- either it needs to have the scheme or at least
+    # one slash for relative links (in contrast, Python names don't have
+    # slashes). If that fails,  turn it into a list and try to look it up in
+    # various dicts.
     def path_to_url(path):
         if isinstance(path, str):
-            if urllib.parse.urlparse(path).netloc: return path
+            if urllib.parse.urlparse(path).netloc or '/' in path: return path
             path = [path]
         entry = state.name_map['.'.join(path)]
         # TODO: this will blow up if linking to something that's not a module,