Creating a node cross-reference to another domain in Sphinx

In the Sphinx user domain, I would like to create a link to another node in another domain. For example:

.. py:class:: foo.bar Lorem ipsum. .. example:directive:: baz -> foo.bar Sit amet, sit. 

My example:directive:: says my baz "method" returns something like foo.bar , which is a Python class. Therefore, I would like to cross-reference another py:class:: foo.bar description py:class:: foo.bar .

 from sphinx.directives import ObjectDescription class ExampleDescription(ObjectDescription): def handle_signature(self, sig, signode): # lots of parsing and node creation here # parsed_annotation = "foo.bar" signode += addnodes.desc_returns(parsed_annotation, parsed_annotation) 

In my user domain, I parse my directives and build elements, and all this is fine, even the cross-reference in my example domain works just fine, subclassing the sphinx.domains.Domain:resolve_xref . I just don't know how to programmatically insert a node into my handle_signature method, which will later be resolved to a node in another domain. Should I somehow create an instance of sphinx.domains.python.PyXRefRole ?

The expected result in HTML will look something like this:

 <dl> <dt> <code>baz</code><a href="example.html#py.class.foo.bar"> <code>foo.bar</code> </a> </dt> </dl> 
+8
python-sphinx docutils
source share

No one has answered this question yet.

See related questions:

23
Link to numbers with numbers in Sphinx and reStructuredText
6
Sphinx Domain for Clojure
3
docutils / sphinx is a user directive that creates a section for sisters, not a child
3
Registry Nesting Sphinx Extension Directives
2
How to create a label reference node above a section in sphinx
one
Sphinx does not create cross-reference link
one
Sphinx issues with cross-reference to python functions
one
Using Cross-References in a Python Domain in Sphinx
0
Sphinx / DocUtils for creating custom documentation
0
Creating a coderef role for sphinx

All Articles