chiark / gitweb /
m.dox: properly extract and use page titles from the tagfile.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 1 Jan 2018 20:05:08 +0000 (21:05 +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 90d18939d79b8bdaea581c9ce48ab0736b14837a..73a82283e992cd177763c7853ad2d1e1e1f7d27f 100644 (file)
@@ -53,56 +53,64 @@ def init(pelicanobj):
                 # Linking to pages
                 if child.attrib['kind'] == 'page':
                     link = path + child.find('filename').text + '.html'
-                    symbol_mapping[child.find('name').text] = link
+                    symbol_mapping[child.find('name').text] = (child.find('title').text, link)
 
                     # Page sections
                     for section in child.findall('docanchor'):
-                        symbol_mapping[section.text] = link + '#' + section.text
+                        symbol_mapping[section.text] = (section.attrib.get('title', ''), link + '#' + section.text)
 
                 # Linking to files
                 if child.attrib['kind'] == 'file':
                     link = path + child.find('filename').text + ".html"
-                    symbol_mapping[child.find('path').text + child.find('name').text] = link
+                    symbol_mapping[child.find('path').text + child.find('name').text] = (None, link)
 
                     for member in child.findall('member'):
                         if not 'kind' in member.attrib: continue
 
                         # Preprocessor defines and macros
                         if member.attrib['kind'] == 'define':
-                            symbol_mapping[member.find('name').text + ('()' if member.find('arglist').text else '')] = link + '#' + member.find('anchor').text
+                            symbol_mapping[member.find('name').text + ('()' if member.find('arglist').text else '')] = (None, link + '#' + member.find('anchor').text)
 
                 # Linking to namespaces, structs and classes
                 if child.attrib['kind'] in ['class', 'struct', 'namespace']:
                     name = child.find('name').text
                     link = path + child.find('filename').text
-                    symbol_mapping[name] = link
+                    symbol_mapping[name] = (None, link)
                     for member in child.findall('member'):
                         if not 'kind' in member.attrib: continue
 
                         # Typedefs, constants
                         if member.attrib['kind'] == 'typedef' or member.attrib['kind'] == 'enumvalue':
-                            symbol_mapping[name + '::' + member.find('name').text] = link + '#' + member.find('anchor').text
+                            symbol_mapping[name + '::' + member.find('name').text] = (None, link + '#' + member.find('anchor').text)
 
                         # Functions
                         if member.attrib['kind'] == 'function':
-                            symbol_mapping[name + '::' + member.find('name').text + "()"] = link + '#' + member.find('anchor').text
+                            symbol_mapping[name + '::' + member.find('name').text + "()"] = (None, link + '#' + member.find('anchor').text)
 
                         # Enums with values
                         if member.attrib['kind'] == 'enumeration':
                             enumeration = name + '::' + member.find('name').text
-                            symbol_mapping[enumeration] = link + '#' + member.find('anchor').text
+                            symbol_mapping[enumeration] = (None, link + '#' + member.find('anchor').text)
 
                             for value in member.findall('enumvalue'):
-                                symbol_mapping[enumeration + '::' + value.text] = link + '#' + value.attrib['anchor']
+                                symbol_mapping[enumeration + '::' + value.text] = (None, link + '#' + value.attrib['anchor'])
 
 def dox(name, rawtext, text, lineno, inliner: Inliner, options={}, content=[]):
     title, target = parse_link(text)
-    if not title: title = target
 
     for prefix in symbol_prefixes:
         if prefix + target in symbol_mapping:
-            url = symbol_mapping[prefix + target]
-            node = nodes.reference(rawtext, title, refuri=url, **options)
+            link_title, url = symbol_mapping[prefix + target]
+            if title:
+                use_title = title
+            elif link_title:
+                use_title = link_title
+            else:
+                if link_title is not None:
+                    logger.warning("Doxygen anchor `{}` has no title, using its ID as link title".format(target))
+
+                use_title = target
+            node = nodes.reference(rawtext, use_title, refuri=url, **options)
             return [node], []
 
     # TODO: print file and line
@@ -110,7 +118,7 @@ def dox(name, rawtext, text, lineno, inliner: Inliner, options={}, content=[]):
         #'Doxygen symbol %s not found' % target, line=lineno)
     #prb = inliner.problematic(rawtext, rawtext, msg)
     logger.warning('Doxygen symbol `%s` not found, rendering as monospace' % target)
-    node = nodes.literal(rawtext, title, **options)
+    node = nodes.literal(rawtext, title if title else target, **options)
     return [node], []
 
 def register():
index 1a8e0c6261ce0f179077579d2fd7da5ee31d36d8..f691e5d01f17801e65ff2b5f78de6ec59160a391 100644 (file)
 <ul>
 <li>Function link: <a href="http://doc.magnum.graphics/corrade/namespaceCorrade_1_1Utility_1_1Directory.html#ad80859f373fbf1ed39b11eb27649c34b">Utility::Directory::mkpath()</a></li>
 <li>Class link: <a href="http://doc.magnum.graphics/corrade/classCorrade_1_1Interconnect_1_1Emitter.html">Interconnect::Emitter</a></li>
-<li>Page link: <a href="http://doc.magnum.graphics/corrade/building-corrade.html">building-corrade</a></li>
+<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>
+</ul>
+<p>These should produce warnings:</p>
+<ul>
+<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>
 </ul>
 <!-- /content -->
       </div>
index fb627b090a78237a440468cb134f14244d728b2b..c27f2f2becf1ea4034f8ff7de71a324df5720f4e 100644 (file)
@@ -5,3 +5,9 @@ m.dox
 -   Class link: :dox:`Interconnect::Emitter`
 -   Page link: :dox:`building-corrade`
 -   :dox:`Custom link title <testsuite>`
+-   :dox:`Page link with custom title <corrade-cmake>`
+
+These should produce warnings:
+
+-   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`