Sphinx从自定义代码引用

时间:2017-08-17 17:15:13

标签: python python-sphinx restructuredtext

我有以下课程:

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。

反问题在这里:Sphinx add code formatting to :ref:

1 个答案:

答案 0 :(得分:1)

我面临同样的问题。我找到的唯一解决方案是写:

"""
Do the thing, but better than the `parent <#my_module.A.x>`_
"""

,它会在生成的HTML页面上创建指向A.x条目的常规ol'超链接。但是,这仅适用于HTML输出;其他格式(例如,LaTeX)将断开链接。

相关问题