Sphinx variable substitution in code blocks

谁都会走 提交于 2019-12-23 07:59:24

问题


Using Sphinx 1.2.3 and given this RST snippet:

.. code-block:: xml

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

and in conf.py I have:

version = '1.0.2'

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

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

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.


回答1:


You can get the wanted output by using backslash-escaped whitespace:

.. parsed-literal::

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

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).



来源:https://stackoverflow.com/questions/27392934/sphinx-variable-substitution-in-code-blocks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!