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):
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>
python-sphinx docutils
deceze
source share