在Sphinx的参考文献中保留内联代码

在Sphinx的参考文献中保留内联代码

本文介绍了在Sphinx的参考文献中保留内联代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在狮身人面像中,如果我有以下标题声明:

In Sphinx, if I have the following heading declaration:

.. _somestuff:

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

它呈现如下:

哪个是好的,但如果我使用引用,例如:

Which is good, but, if I use the reference, e.g:

Have a look at :ref:`somestuff`

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

It loses the code formatting and renders like:

    看看

    Have a look at this is code, this is not!

而不是:

    看看

    Have a look at this is code, this is not!

是吗可能在引用中保留代码格式?那么我该怎么办?

Is it possible to retain the code formatting in the reference? And how would I go about it?

推荐答案

如果你看看:ref: code>文档在关于内联标记:

If you have a look at :ref: documentation in its official web site about inline markups:

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

To support cross-referencing to arbitrary locations in any document, the standard reST labels are used. For this to work label names must be unique throughout the entire documentation ...

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

I think (as @Kevin Horn) it's no possible right now, because it's only used to create links (without rst formatting) with other sections in your project. Then if you write something like this:

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

结果是:

看看 这是代码,这不是!

Have a look at this is code, this is not!

看看 这是另一个代码!

查看 此链接

Have a look at this link

所有这些都是一样的。

注意:斜体/粗体字符号链接

Note: the italic/bold words symbolize links

这篇关于在Sphinx的参考文献中保留内联代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 22:12