如何在代码块中包含内部引用? [英] How to include an internal reference in a code block?
问题描述
在我的 Sphinx .rst 文档中,我有一个代码块,其中包含使用 UNIX tree
命令的产品结构的树视图:
In my Sphinx .rst document I have a code block containing a tree view of the structure of my product using the UNIX tree
command:
|── parent
| |── child
| |── grandchild
它位于代码块中,以便 Sphinx 保留空格.
It's in a code block so that Sphinx preserves the whitespaces.
我希望读者能够点击每个节点来关注 内部超链接 到描述该节点的文档部分.但是,在代码块中添加 :ref:
不起作用(见下文).有谁知道如何实现这一目标?
I want readers to be able to click on each node to follow an internal hyperlink to the part of the document that describes that node. However, adding a :ref:
inside the code block doesn't work (see below). Does anyone know how to achieve this?
这不起作用:
.. _parent:
Parent
------
Blah blah
.. _child:
Child
-----
Blah blah
.. _grandchild:
Grandchild
----------
Blah blah
那么……:
|── :ref:`parent`
| |── :ref:`child`
| |── :ref:`grandchild`
推荐答案
您可以使用 parsed-literal
指令:
You can use the parsed-literal
directive:
.. parsed-literal::
|── :ref:`parent`
| |── :ref:`child`
| |── :ref:`grandchild`
这有效,但有警告消息说警告:内联替换引用起始字符串没有结束字符串."
This works, but there are warning messages saying "WARNING: Inline substitution_reference start-string without end-string."
竖线被解释为替代参考.警告会随着一些转义而消失:
The vertical bars are interpreted as parts of substitution references. The warnings go away with some escaping:
.. parsed-literal::
\|── :ref:`parent`
| \|── :ref:`child`
| \|── :ref:`grandchild`
这篇关于如何在代码块中包含内部引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!