chiark / gitweb /
m.dox: ability to link to documentation index pages.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 1 Jan 2018 20:09:03 +0000 (21:09 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Mon, 1 Jan 2018 20:37:15 +0000 (21:37 +0100)
pelican-plugins/m/dox.py
pelican-plugins/m/test/dox/page.html
pelican-plugins/m/test/dox/page.rst

index 083ddb0297104de0f52768e004eb6dd6519b9004..f3c35d9e083e95708c092c3844065b0ca871eb17 100644 (file)
@@ -28,6 +28,7 @@ from docutils import nodes, utils
 from docutils.parsers import rst
 from pelican import signals
 import xml.etree.ElementTree as ET
+import os
 
 import logging
 
@@ -35,15 +36,17 @@ logger = logging.getLogger(__name__)
 
 symbol_mapping = {}
 symbol_prefixes = ['']
+tagfile_basenames = []
 
 def init(pelicanobj):
-    global symbol_mapping, symbol_prefixes
+    global symbol_mapping, symbol_prefixes, tagfile_basenames
 
     tagfiles = pelicanobj.settings.get('M_DOX_TAGFILES', [])
 
     # Pre-round to populate subclasses
 
     for tagfile, path, prefixes in tagfiles:
+        tagfile_basenames += [(os.path.splitext(os.path.basename(tagfile))[0], path)]
         symbol_prefixes += prefixes
 
         tree = ET.parse(tagfile)
@@ -98,6 +101,17 @@ def init(pelicanobj):
 def dox(name, rawtext, text, lineno, inliner: Inliner, options={}, content=[]):
     title, target = parse_link(text)
 
+    # Try linking to the whole docs first
+    for basename, url in tagfile_basenames:
+        if basename == target:
+            if not title:
+                # TODO: extract title from index page in the tagfile
+                logger.warning("Link to main page `{}` requires a title".format(target))
+                title = target
+
+            node = nodes.reference(rawtext, title, refuri=url, **options)
+            return [node], []
+
     for prefix in symbol_prefixes:
         if prefix + target in symbol_mapping:
             link_title, url = symbol_mapping[prefix + target]
index a30bf77a5ae35d92c6f212302997addd592f9404..fc0d953a67c1723fe1ef0235497a304b410542af 100644 (file)
@@ -29,6 +29,7 @@
 <li>Page link: <a href="http://doc.magnum.graphics/corrade/building-corrade.html">Downloading and building</a></li>
 <li><a href="http://doc.magnum.graphics/corrade/testsuite.html">Custom link title</a></li>
 <li><a href="http://doc.magnum.graphics/corrade/corrade-cmake.html">Page link with custom title</a></li>
+<li><a href="http://doc.magnum.graphics/corrade/">Link to index page</a></li>
 </ul>
 <p>These should produce warnings:</p>
 <ul>
@@ -36,6 +37,8 @@
 <li><span>Link to nonexistent name with custom title will be just text</span></li>
 <li>Link to a section that doesn't have a title will keep the ID (this <em>may</em>
 break on tagfile update, watch out): <a href="http://doc.magnum.graphics/corrade/corrade-cmake.html#corrade-cmake-add-test">corrade-cmake-add-test</a></li>
+<li>Link to index page without title will have the tag file basename:
+<a href="http://doc.magnum.graphics/corrade/">corrade</a></li>
 </ul>
 <!-- /content -->
       </div>
index 74b32710012da70485347455a78e901ef3605b5c..47102b94d100b911433afc57393d34d26157c79f 100644 (file)
@@ -6,6 +6,7 @@ m.dox
 -   Page link: :dox:`building-corrade`
 -   :dox:`Custom link title <testsuite>`
 -   :dox:`Page link with custom title <corrade-cmake>`
+-   :dox:`Link to index page <corrade>`
 
 These should produce warnings:
 
@@ -13,3 +14,5 @@ These should produce warnings:
 -   :dox:`Link to nonexistent name with custom title will be just text <nonExistent()>`
 -   Link to a section that doesn't have a title will keep the ID (this *may*
     break on tagfile update, watch out): :dox:`corrade-cmake-add-test`
+-   Link to index page without title will have the tag file basename:
+    :dox:`corrade`