Skip to main content

Extensions for Sphinx which allow for substitutions.

Project description

Build Status codecov PyPI

Sphinx Substitution Extensions

Extensions for Sphinx which allow substitutions within code blocks.

Installation

Sphinx Substitution Extensions is compatible with Sphinx 8.2.0+ using Python 3.10+.

$ pip install Sphinx-Substitution-Extensions

rST setup

  1. Add the following to conf.py to enable the extension:

"""Configuration for Sphinx."""

extensions = ["sphinxcontrib.spelling"]  # Example existing extensions

extensions += ["sphinx_substitution_extensions"]
  1. Set the following variable in conf.py to define substitutions:

"""Configuration for Sphinx."""

rst_prolog = """
.. |release| replace:: 0.1
.. |author| replace:: Eleanor
"""

This will replace |release| in the new directives with 0.1, and |author| with Eleanor.

Using substitutions in rST documents

code-block

This adds a :substitutions: option to Sphinx’s built-in code-block directive.

.. code-block:: shell
   :substitutions:

   echo "|author| released version |release|"

Inline :substitution-code:

:substitution-code:`echo "|author| released version |release|"`

substitution-download

:substitution-download:`|author|'s manuscript <|author|_manuscript.txt>`

MyST Markdown setup

  1. Add sphinx_substitution_extensions to extensions in conf.py to enable the extension:

"""Configuration for Sphinx."""

extensions = ["myst_parser"]  # Example existing extensions

extensions += ["sphinx_substitution_extensions"]
  1. Set the following variables in conf.py to define substitutions:

"""Configuration for Sphinx."""

myst_enable_extensions = ["substitution"]

myst_substitutions = {
    "release": "0.1",
    "author": "Eleanor",
}

This will replace |release| in the new directives with 0.1, and |author| with Eleanor.

Using substitutions in MyST Markdown

code-block

This adds a :substitutions: option to Sphinx’s built-in code-block directive.

```{code-block} bash
   :substitutions:

   echo "|author| released version |release|"
```

As well as using |author|, you can also use {{author}}. This will respect the value of myst_sub_delimiters as set in conf.py.

Inline :substitution-code:

{substitution-code}`echo "|author| released version |release|"`

substitution-download

{substitution-download}`|author|'s manuscript <|author|_manuscript.txt>`

Credits

ClusterHQ Developers

This package is largely inspired by code written for Flocker by ClusterHQ. Developers of the relevant code include, at least, Jon Giddy and Tom Prince.

Contributing

See CONTRIBUTING.rst.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx_substitution_extensions-2025.6.6.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

sphinx_substitution_extensions-2025.6.6-py2.py3-none-any.whl (7.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sphinx_substitution_extensions-2025.6.6.tar.gz.

File metadata

File hashes

Hashes for sphinx_substitution_extensions-2025.6.6.tar.gz
Algorithm Hash digest
SHA256 241ddb9f88962422a8b436243d2601f9d94616e94b520ce1a6a528d9a3b7804a
MD5 7da12a21651b5965e722f304ffa1092f
BLAKE2b-256 af9286cfb27705791652a54d42f35409a5128fc29395fbe38039222fe15116ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinx_substitution_extensions-2025.6.6.tar.gz:

Publisher: release.yml on adamtheturtle/sphinx-substitution-extensions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sphinx_substitution_extensions-2025.6.6-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_substitution_extensions-2025.6.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 96206ba7a2cdf43237edec81f87770a5683a91a1de3bf93f7a22309509ecbfd8
MD5 fceaaf019a3335a0d364fd0c0374e9f5
BLAKE2b-256 ba11d81677eb3dcd9b130cf97169ebf762170ade3fa676395329d59f9cf1540a

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinx_substitution_extensions-2025.6.6-py2.py3-none-any.whl:

Publisher: release.yml on adamtheturtle/sphinx-substitution-extensions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page