Sphinx 从自定义代码参考中删除代码格式 [英] Sphinx remove code formatting from custom code reference
问题描述
我有以下课程:
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
ed.我想要一个链接到 x
的父实现,它呈现为父",而不是parent
".如何从自定义方法引用中删除代码格式?
The entire module is autodoc
ed. I would like to have a link to the parent implementation of x
that renders as "parent", not as "parent
". How do I remove the code formatting from the custom method reference?
根据 交叉引用格式.
这是为链接生成的 HTML:
Here is the generated HTML for the link:
<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 标签之间没有中断或空格.]
[Line breaks inserted by me for legibility. Original HTML has no breaks or spaces between tags.]
我在 Anaconda 环境中使用 Sphinx 1.6.3 和 Python 3.6.2.
I am using Sphinx 1.6.3 with Python 3.6.2 in an Anaconda environment.
反向问题在这里:Sphinx 将代码格式添加到 :ref:
推荐答案
我面临同样的问题.我找到的唯一解决方案是编写:
I am facing the same problem. The only solution I have found is to write:
"""
Do the thing, but better than the `parent <#my_module.A.x>`_
"""
它会在生成的 HTML 页面上创建一个指向 A.x
条目的常规 ol' 超链接.但是,这只适用于 HTML 输出;其他格式(例如 LaTeX)的链接将失效.
which creates a regular ol' hyperlink to the A.x
entry on the generated HTML page. However, this only works for HTML output; other formats (e.g., LaTeX) will have broken links.
这篇关于Sphinx 从自定义代码参考中删除代码格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!