Substitutions inside Sphinx code blocks aren't replaced

Use the "parsed-literal" directive.

.. parsed-literal::

    ./home/user/somecommand-|version|

Source: https://groups.google.com/forum/?fromgroups=#!topic/sphinx-dev/ABzaUiCfO_8:


Found a better solution (in my opinion), that can be used in others directives like :samp: and might be useful for future readers.

config.py:

def ultimateReplace(app, docname, source):
    result = source[0]
    for key in app.config.ultimate_replacements:
        result = result.replace(key, app.config.ultimate_replacements[key])
    source[0] = result

ultimate_replacements = {
    "{TEST}" : "replaced"
}

def setup(app):
   app.add_config_value('ultimate_replacements', {}, True)
   app.connect('source-read', ultimateReplace)

And this kind of markup:

.. http:get:: testing/replacement/{TEST}

Properly generates like:

testing/replacement/replaced

Note, that if using this to replace an argument in the :samp: directive, a double bracket { is require.

:samp:`func({{TEST}})`.

source: https://github.com/sphinx-doc/sphinx/issues/4054