In Sphinx, can I register a bunch of keywords that should always be translated into links?

My document lines have links to other python classes that I defined. Every time Sphinx comes across one of these classes, I want it to insert a documentation link for this other class. Is this possible in Sphinx?

In particular, I have a document line, for example:

'''This class contains a bunch of Foo objects'''

I could write:

'''This class contains a bunch of :class:`~foo.Foo` objects'''

but I would prefer Sphinx to detect that all text matches Fooand it looks like I typed: Class:~foo.Foo

+5
source share
2 answers

You can use macros.

, "" . :

.. |PostItem| replace:: :class:`PostItem <hklib.PostItem>`
.. |PostNotFoundError| replace:: :class:`PostNotFoundError <hklib.PostNotFoundError>`

rst . rst:

.. include:: defs.hrst

|PostItem| is a nice class. |PostNotFoundError|, on the other hand is not.

( docstrings Python, autogen. .)

: Foo docstring :

'''This class contains a bunch of |Foo| objects'''
+7

Sphinx .

http://sphinx.pocoo.org/markup/inline.html#cross-referencing-python-objects

Foo Sphinx , : class: ~foo.Foo

. , RST, . , RST (*_|`), - , .

, , , RST , Foo ​​, . , Foo; .

docstring.

http://sphinx.pocoo.org/ext/autodoc.html#docstring-preprocessing

.

+2

All Articles