I am documenting a set of projects using Sphinx that benefits greatly from the intersphinx extension. Essentially, there are about 3 utility projects that feed into a larger one, and in the larger project I need to reference the documentation from the smaller ones. I have intersphinx set up as
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
...
]
intersphinx_mapping = {
'project1': ('http://internal.url/to/project1/latest', None),
'project2': ('http://internal.url/to/project2/latest', None),
'project3': ('http://internal.url/to/project3/latest', None),
}
This lets me use intersphinx normally:
:any:`project1.Class1`
Which gets rendered as a link with the text project1.Class1. I would rather it use the unqualified name, though, so I end up writing
:any:`Class1 <project1.Class1>`
a lot. This is annoying. I would really like to set up a handful of roles so that I could do
* :p1:`Class1` is from ``project1``
* :p2:`Class2` is from ``project2``
* :p3:`function1` is from ``project3``
where :p1:`{text}` is replaced by :any:`{text} <project1.{text}>`, etc.
Is there an easy way to do this? All of my searches have come up with pretty useless information and the source code for the intersphinx is pretty hard to read. Ideally there would be some way for me to just do
def p1_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
return sphinx.some_module.parse(':any:`{0} <project1.{0}>`'.format(text))
def setup(app):
app.add_role('p1', p1_role)
would be the best, but I don't know if that is available anywhere.