From 2b4a0a27fccf75e7080028cd0856a60a5269a8bf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 1 Jan 2018 21:05:08 +0100 Subject: [PATCH] m.dox: properly extract and use page titles from the tagfile. --- pelican-plugins/m/dox.py | 34 +++++++++++++++++----------- pelican-plugins/m/test/dox/page.html | 8 ++++++- pelican-plugins/m/test/dox/page.rst | 6 +++++ 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/pelican-plugins/m/dox.py b/pelican-plugins/m/dox.py index 90d18939..73a82283 100644 --- a/pelican-plugins/m/dox.py +++ b/pelican-plugins/m/dox.py @@ -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(): diff --git a/pelican-plugins/m/test/dox/page.html b/pelican-plugins/m/test/dox/page.html index 1a8e0c62..f691e5d0 100644 --- a/pelican-plugins/m/test/dox/page.html +++ b/pelican-plugins/m/test/dox/page.html @@ -26,8 +26,14 @@ +

These should produce warnings:

+ diff --git a/pelican-plugins/m/test/dox/page.rst b/pelican-plugins/m/test/dox/page.rst index fb627b09..c27f2f2b 100644 --- a/pelican-plugins/m/test/dox/page.rst +++ b/pelican-plugins/m/test/dox/page.rst @@ -5,3 +5,9 @@ m.dox - Class link: :dox:`Interconnect::Emitter` - Page link: :dox:`building-corrade` - :dox:`Custom link title ` +- :dox:`Page link with custom title ` + +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` -- 2.30.2