【问题标题】:Sphinx remove code formatting from custom code referenceSphinx 从自定义代码参考中删除代码格式
【发布时间】:2017-08-17 17:15:12
【问题描述】:

我有以下课程:

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

整个模块是autodoced。我想要一个指向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:

【问题讨论】:

  • 您可以编辑您的问题以包含 HTML 输出吗?我认为您也许可以在主题的 CSS 中添加自定义样式,使其显示为普通的非等宽字体。
  • @StevePiercy。完成
  • AFAIK,Sphinx 不支持内联代码的自定义样式。您可以尝试使用疯狂选择器的 CSS,例如 a[href!#my_module.A.x]&gt;code&gt;span,以及使用 !important 覆盖 pre 类的样式。
  • 我完全可以为此定义一个自定义角色。例如,名为:py:methref: 的东西。我会研究如何做到这一点。

标签: python python-sphinx restructuredtext


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2019-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-26
    • 1970-01-01
    相关资源
    最近更新 更多