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

编程入门 行业动态 更新时间:2024-10-28 02:34:46
本文介绍了在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:

:ref:

为了支持交叉引用到任意任何文件中的位置,使用标准的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的参考文献中保留内联代码

本文发布于:2023-10-09 10:41:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1475518.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内联   参考文献   代码   Sphinx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!