在Sphinx中保留引用中的内联代码

tjm*_*tjm 35 documentation restructuredtext documentation-generation python-sphinx

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

.. _somestuff:

``this is code``, this is not!
==============================
Run Code Online (Sandbox Code Playgroud)

它渲染,像这样:

    this is code, 这不是!

哪个好,但是,如果我使用参考,例如:

Have a look at :ref:`somestuff`
Run Code Online (Sandbox Code Playgroud)

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

    看看这是代码,这不是!

代替:

    看看this is code,这不是!


是否可以在引用中保留代码格式?我该怎么办呢?

fen*_*688 3

如果您查看:ref:官方网站中有关内联标记的文档:

:参考:

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

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

.. _somestuff:

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

.. _another_somestuff:

this is another code!
========================
Run Code Online (Sandbox Code Playgroud)

如果我链接到这些部分:

Have a look at :ref:`somestuff`
Have a look at :ref:`another_somestuff`
Have a look at :ref:`this link <somestuff>`
Run Code Online (Sandbox Code Playgroud)

结果是:


看看这是代码,这不是!

看看这是另一个代码!

看看这个链接


它们的风格都是一样的。

:斜体/粗体字表示链接