Extensions for Sphinx which allow for substitutions.
Project description
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
Add the following to conf.py to enable the extension:
"""Configuration for Sphinx."""
extensions = ["sphinxcontrib.spelling"] # Example existing extensions
extensions += ["sphinx_substitution_extensions"]
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
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"]
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.
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
Release history Release notifications | RSS feed
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.10.17.tar.gz
.
File metadata
- Download URL: sphinx_substitution_extensions-2024.10.17.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30fa723bb44afe23adc5187601dcf0c1955dcd1b26f588773b395e852076179d |
|
MD5 | 887845acd3a950f9b9852c02ecde0ec8 |
|
BLAKE2b-256 | 7684dd9f95819e8fb5b799cb3e6269ebab2e1ff734e0c09e1223c3d1231ba9e0 |
File details
Details for the file sphinx_substitution_extensions-2024.10.17-py2.py3-none-any.whl
.
File metadata
- Download URL: sphinx_substitution_extensions-2024.10.17-py2.py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c1aae08edea616c5602f30368e6c15205220aa2d0b37bc47569322bce5e1271 |
|
MD5 | 3da577200c5dcff21bc725d8b18d6496 |
|
BLAKE2b-256 | 5495dd46a2ef9ad26d7e4c2e889bc714d744deb7b4b069d2264412716ee2db33 |