Sphinx remove code formatting from custom code reference

假如想象 提交于 2019-12-07 22:01:16

问题


I have the following classes:

class A:
    def x():
        """ Do the thing. """
class B(A):
    def x():
        """
        Do the thing, but better than the :py:meth:`parent <A.x>`
        """

The entire module is autodoced. 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?

The link itself is interpreted correctly based on the first rule of cross reference formats.

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>

[Line breaks inserted by me for legibility. Original HTML has no breaks or spaces between tags.]

I am using Sphinx 1.6.3 with Python 3.6.2 in an Anaconda environment.

Inverse question is here: Sphinx add code formatting to :ref:


回答1:


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>`_
"""

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.



来源:https://stackoverflow.com/questions/45741326/sphinx-remove-code-formatting-from-custom-code-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!