【问题标题】:Prevent term ending in an underscore from appearing as hyperlink in Sphinx docs防止以下划线结尾的术语在 Sphinx 文档中显示为超链接
【发布时间】:2020-09-25 16:43:28
【问题描述】:

我有一个类方法,其参数以下划线结尾,from_,我正在使用autoclass 生成该类的文档。我希望参数 from_ 在我的 Sphinx 文档中显示为普通文本,但目前它显示为超链接。

这是一个带有文档字符串的类方法的简化版本:

class Twilio:

    def get_messages(to=None, from_=None):
        """
        Get messages.

        `Args:`
            to: str
                Receiver.
            from_: str
                Sender.
        `Returns:`
            Messages: dict
        """
        return fetch_messages(to=to, from_=from_)

我正在为这个类生成文档:

.. autoclass :: Twilio
   :inherited-members:

问题可以在这个page最底部的get_messages函数中看到,你可以看到它被格式化为超链接。

【问题讨论】:

  • 请发布您的 reST 标记。在那之前,您可以通过用双反引号“`”将其括起来使其成为内联文字。
  • 抱歉,我添加了澄清代码,还有一个在线文档链接,您目前可以在最底部看到函数中的错误。
  • 信息还不够。我们需要您的方法和方法本身的完整文档字符串。
  • 好的,很抱歉,感谢您的耐心等待。希望我刚刚添加的内容就足够了。

标签: python-sphinx restructuredtext


【解决方案1】:

使用反斜杠转义下划线。

from\_: str
     Sender.

参考:https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#escaping-mechanism

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    • 2016-06-04
    • 2012-04-29
    相关资源
    最近更新 更多