我有以下课程:
class A:
def x():
""" Do the thing. """
class B(A):
def x():
"""
Do the thing, but better than the :py:meth:`parent <A.x>`
"""
整个模块autodoc
。我希望有一个指向x
的父实现的链接,该实现呈现为“父”,而不是“parent
”。如何从自定义方法引用中删除代码格式?
根据cross reference formats的第一条规则正确解释链接本身。
以下是为链接生成的HTML:
<a class="reference internal" href="#my_module.A.x" title="my_module.A.x">
<code class="xref py py-meth docutils literal">
<span class="pre">parent</span>
</code>
</a>
[由我插入换行符以表示易读性。原始HTML在标记之间没有间隔或空格。]
我在Anaconda环境中使用Sphinx 1.6.3和Python 3.6.2。
答案 0 :(得分:1)
我面临同样的问题。我找到的唯一解决方案是写:
"""
Do the thing, but better than the `parent <#my_module.A.x>`_
"""
,它会在生成的HTML页面上创建指向A.x
条目的常规ol'超链接。但是,这仅适用于HTML输出;其他格式(例如,LaTeX)将断开链接。