【问题标题】:Retaining inline code inside references in Sphinx在 Sphinx 中的引用中保留内联代码
【发布时间】:2011-12-26 21:05:01
【问题描述】:

在 Sphinx 中,如果我有以下标题声明:

.. _somestuff:

``this is code``, this is not!
==============================

它呈现如下:

    this is code,这不是!

这很好,但是,如果我使用参考,例如:

Have a look at :ref:`somestuff`

它丢失了代码格式并呈现如下:

    看看this is code, this is not!

代替:

    看看this is code, this is not!


是否可以在参考中保留代码格式?我该怎么做?

【问题讨论】:

  • 我认为现在不可能。我很确定 :ref: 角色只是拉链接,并忽略任何其他 rst 格式。您可以尝试将此作为错误/功能请求报告给 Sphinx 开发人员。
  • 这里有一个解决方法:stackoverflow.com/a/51666008/407651

标签: python-sphinx restructuredtext cross-reference


【解决方案1】:

如果您在其official web site 中查看:ref: 关于内联标记的文档:

:ref:

为了支持对任何文档中任意位置的交叉引用, 使用标准的 reST 标签。为此,标签名称必须 在整个文档中保持唯一...

我认为(作为@Kevin Horn)现在不可能,因为它仅用于创建与项目中其他部分的链接(没有 rst 格式)。那么如果你写这样的东西:

.. _somestuff:

``this is code``, this is not!
==============================

.. _another_somestuff:

this is another code!
========================

如果我链接到这些部分:

Have a look at :ref:`somestuff`
Have a look at :ref:`another_somestuff`
Have a look at :ref:`this link <somestuff>`

结果是:


看看这是代码,这不是!

看看这是另一个代码!

看看这个链接


风格都是一样的

注意:斜体/粗体字表示链接

【讨论】:

    猜你喜欢
    • 2021-08-01
    • 2014-03-02
    • 2017-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-10
    • 1970-01-01
    相关资源
    最近更新 更多