代码块中的Sphinx变量替换 [英] Sphinx variable substitution in code blocks

查看:88
本文介绍了代码块中的Sphinx变量替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Sphinx 1.2.3并提供以下RST代码段:

Using Sphinx 1.2.3 and given this RST snippet:

.. code-block:: xml

    <foo>
        <bar>|version|</bar>
    </foo>

conf.py中,我有:

version = '1.0.2'

如何确保上面的RST代码段呈现为:

How do you ensure that the above RST snippet renders as:

<foo>
    <bar>1.0.2</bar>
</foo>

上一个问题表示我们应该使用.. parsed-literal::而不是,但这无效,该问题中的引用链接也无效.

This previous question indicates that we should use .. parsed-literal:: instead of .. code-block::, but that does not work, nor does the referenced link in that question work either.

我还想保留语法突出显示.

I also want to retain syntax highlighting.

推荐答案

您可以使用反斜杠转义的空格:

.. parsed-literal::

  <foo>
       <bar>\ |release|\ </bar>
  </foo>

不幸的是,不可能同时保留语法高亮显示(当然可以通过code-block指令来获取,但是替换将无法正常工作.)

Unfortunately it is not possible to also retain syntax highlighting (you can get that with the code-block directive of course, but then the substitution won't work).

这篇关于代码块中的Sphinx变量替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆