如何在Sphinx中交叉引用autodoc生成的函数? [英] How would I cross-reference a function generated by autodoc in Sphinx?
问题描述
我正在使用 Sphinx autodoc
功能根据我的Python库的文档字符串生成文档。
I am using the Sphinx autodoc
feature to generate documentation based on the docstrings of my Python library.
可以在此处找到交叉引用的语法
The syntax for cross referencing is found here
标签必须位于该部分之前,以便允许从文档的其他区域引用该部分。
A label must precede the section in order to allow that section to be referenced from other areas of the documentation.
我拥有什么是我的一个类的.rst(ReStructeredText)文件。它使用
What I have is a .rst (ReStructeredText) file for one of my classes. It uses
.. autoclass:: classname
:members:
为班级生成文档。
我的问题是,我如何引用自动从文档中的另一个.rst文档生成类的方法?如果我尝试在方法的文档字符串中放置标签,Sphinx会抱怨。如果我尝试在方法标题之前放置一个标签,Sphinx就无法识别它。
My question is, how would I reference the auto-generated methods of the class from another .rst document in the documentation? If I try to place a label within the method's docstring, Sphinx complains. If I try to place a label before the method heading, Sphinx doesn't recognize it.
有一种简单的方法可以做到这一点,还是我必须明确写出来在我的类文件中的方法名称并在其前面加上标签?
Is there a simple way to do this, or will I have to explicitly write in my class file the method name and precede that with a label?
这是[Python文档 2 做我需要的东西(我假设它使用了autodoc功能,虽然我不确定)
Here is an example a reference within the [Python documentation2 doing what I need (I am assuming it used the autodoc feature, though I don't know for sure)
推荐答案
您无需添加标签。要引用Python类,方法或其他文档化对象,请使用 Python域提供的标记一>。
You don't need to add labels. In order to refer to a Python class, method, or other documented object, use the markup provided by the Python domain.
例如,以下定义了对 mymethod
方法的交叉引用:
For example, the following defines a cross-reference to the mymethod
method:
:py:meth:`mymodule.MyClass.mymethod`
甚至更简单(因为Python域是默认值):
Or even simpler (since the Python domain is the default):
:meth:`mymodule.MyClass.mymethod`
TextWrapper.wrap 的文档您在问题中链接到的code>
包括两种此类交叉引用(单击显示源以查看reST标记)。
The documentation of TextWrapper.wrap
that you link to in the question includes two cross-references of this kind (click on "Show Source" to see the reST markup).
这篇关于如何在Sphinx中交叉引用autodoc生成的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!