Rearrange Sphinx variables in code blocks

Using Sphinx 1.2.3 and considering this RST snippet:

.. code-block:: xml <foo> <bar>|version|</bar> </foo> 

and in conf.py I have:

 version = '1.0.2' 

How do you guarantee that the above RST snippet is displayed as:

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

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

I also want to keep syntax highlighting.

+8
source share
1 answer

You can get the desired output with running backslash spaces :

 .. parsed-literal:: <foo> <bar>\ |release|\ </bar> </foo> 

Unfortunately, it is also impossible to keep syntax highlighting (you can get this using the code-block directive, but then the replacement will not work).

+6
source

Source: https://habr.com/ru/post/979376/


All Articles