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 7.2.0+ using Python 3.10+.

$ pip install Sphinx-Substitution-Extensions

rST setup

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

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

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:: bash
   :substitutions:

   echo "|author| released version |release|"

prompt

This adds a :substitutions: option to sphinx-prompt.

.. prompt:: bash
   :substitutions:

   echo "|author| released version |release|"

Inline :substitution-code:

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

MyST Markdown setup

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

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

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|"
```

Credits

sphinx-prompt authors

Thanks to @sbrunner and other contributors for sphinx-prompt. substitution-prompt is based on sphinx-prompt.

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

Built Distribution

File details

Details for the file sphinx-substitution-extensions-2024.2.24.1.tar.gz.

File metadata

File hashes

Hashes for sphinx-substitution-extensions-2024.2.24.1.tar.gz
Algorithm Hash digest
SHA256 5a6575bd66cdb36e300bef7fd5a5c4a79f5930ffc0960ffd4da18068cff09c86
MD5 1931351b86ee3764f4e69e0d3708af0a
BLAKE2b-256 3c36d6c6554a45b9a8f2c4d03846c0ac80a4dea556cbddab0d8ee5ec736212cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sphinx_substitution_extensions-2024.2.24.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d843c254f73935914b3eb47a8be06ee3d427ae0acf53ffa1bb3a06e9319f4166
MD5 c3ffebc5a0684e699982638721625cc6
BLAKE2b-256 2a829bae5239f2b29304804cf59e6826979ca4b89c466258be50df2c171069d2

See more details on using hashes here.

Supported by

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