intersphinx: explicitly parse out inventory specification

This commit is contained in:
Jakob Lykke Andersen 2021-07-13 13:41:41 +02:00
parent 454a1c599e
commit 36c6eafdf1
3 changed files with 16 additions and 0 deletions

View File

@ -495,10 +495,20 @@ class IntersphinxRole(SphinxRole):
location=(self.env.docname, self.lineno))
return [], []
# extract inventory specification
inventory = None
if self.text.startswith('\\:'):
# escaped :, so not a real inventory specification
self.text = self.text[1:]
elif self.text[0] == ':': # format: :inv:normalRoleArg
inventory = self.text.split(':')[1]
self.text = self.text[(len(inventory) + 2):]
result, messages = self.invoke_role(role_name)
for node in result:
if isinstance(node, pending_xref):
node['intersphinx'] = True
node['inventory'] = inventory
return result, messages
@ -555,6 +565,9 @@ class IntersphinxRoleResolver(ReferencesResolver):
for node in self.document.traverse(pending_xref):
if 'intersphinx' in node:
contnode = cast(nodes.TextElement, node[0].deepcopy())
# temporary hax to glue on inventory info again
if node['inventory'] is not None:
node['reftarget'] = node['inventory'] + ":" + node['reftarget']
newnode = missing_reference(self.app, self.env, node, contnode)
if newnode is None:
# no warning, the normal missing_reference handler will do that

View File

@ -20,6 +20,7 @@
:external:cpp:type:`std::uint8_t`
:external:cpp:class:`inv:foo::Bar`
:external:cpp:func:`:inv2:foo::Bar::baz`
:external:cpp:type:`FoonsTitle <foons>`
:external:cpp:type:`inv:BarType <foons::bartype>`

View File

@ -558,3 +558,5 @@ def test_intersphinx_role(app):
html = '<a class="reference external" href="http://example.org/{}" title="(in foo v2.0)">'
for t in targets:
assert html.format(t) in content
assert html.format('index.html#cpp_foo_bar_baz') not in content