This package is an extension for Sphinx that creates a '-start' companion and a '-end' companion for every registered class-based directive.
Project description
Sphinx Gated Directives
This package is an extension for Sphinx that creates a start directive and an end directive for every registered class-based directive.
What does it do?
This extension performs the following steps:
- It scans the Sphinx environment for all registered class-based directives.
- For each directive found, it automatically registers two new directives:
- A start directive that marks the beginning of a block.
- An end directive that marks the end of a block.
- On build time, it processes these start and end directives to ensure that content between them is handled correctly.
For example, if you have a directive called warning, this extension will create (with default settings) two new directives: warning-start and warning-end. The code:
:::{warning}
This is a warning message.
So, be careful!
:::
can now be replaced with the code
:::{warning-start}
This is a warning message.
:::
So, be careful!
:::{warning-end}
:::
In short:
- This extension splits the original directive into a start and end directive.
- The start directive has the same options as the original directive.
- Anything inside the start directive is processed as usual.
- Anything between the start and end directives is processed as usual, and then added to the output of the start directive.
- The end directive is mandatory to close the directive.
- Anything inside the end directive is ignored.
This allows two things:
- More granular control over where the directive starts and ends, which can be useful in complex documents. This is similar to how HTML tags and LaTeX environments work.
- The ability to nest directives more easily, as the start and end markers can be placed independently. A major benefit of this is that it allows for nesting of code-cells.
[!CAUTION] Some directives parse the content inside the directive. If that content is moved between the start and end directives, it may not be parsed as expected, as it will be parsed separately.
Installation
To use this extension, follow these steps:
Step 1: Install the Package
Install the module sphinx-gated-directives package using pip:
pip install sphinx-gated-directives
Step 2: Add to requirements.txt
Make sure that the package is included in your project's requirements.txt to track the dependency:
sphinx-gated-directives
Step 3: Enable in _config.yml
In your _config.yml file, add the extension to the list of Sphinx extra extensions (important: underscore, not dash this time):
sphinx:
extra_extensions:
.
.
.
- sphinx_gated_directives
.
.
.
or similarly in your conf.py file.
Configuration
This extension can be configured via the _config.yml file in your JupyterBook project (or similarly in conf.py for standard Sphinx projects).
The default configuration options are as follows:
sphinx:
config:
sphinx_gated_directives:
suffix_start: start # Suffix for the start directive
suffix_end: end # Suffix for the end directive
suffix_separator: '-' # Separator between the original directive name and the suffix
override_existing: false # Whether to override existing gated directives with the same name
Per key the meanings are:
suffix_start: The suffix to append to the original directive name for the start directive.- Default is
start. - Must be a non-empty string containing only
a-z.
- Default is
suffix_end: The suffix to append to the original directive name for the end directive.- Default is
end. - Must be a non-empty string containing only
a-z.
- Default is
suffix_separator: The separator to use between the original directive name and the suffix.- Default is
-. - Must be a single character, no space, no underscore, no colon, or empty string.
- Default is
override_existing: Whether to override existing gated directives with the same name.- Default is
false. - Must be a boolean value (
trueorfalse), a single string or a list of strings. - If
false, none existing gated directives will be overridden. - If
true, all existing gated directives will be overridden. - If a string or a list of strings, only the existing gated directives with names in the list/string will be overridden.
- Default is
[!WARNING] Setting
override_existingto anything other thanfalsemay lead to unexpected behavior if those directives are already in use.Use with caution.
Examples
Examples for this extension is available in the TeachBooks manual.
Contribute
This tool's repository is stored on GitHub. If you'd like to contribute, you can create a fork and open a pull request on the GitHub repository.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sphinx_gated_directives-1.0.2.tar.gz.
File metadata
- Download URL: sphinx_gated_directives-1.0.2.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16df805c76e4620b5c28e13d1c33ea72d3bbe9d2f3651819ec410b0031651537
|
|
| MD5 |
bab858342a1c0d3e6c958a0dea66c39b
|
|
| BLAKE2b-256 |
99b20174cc6a717199db708236e83adf57b3687723196a7c2f5da64c1d57fdec
|
Provenance
The following attestation bundles were made for sphinx_gated_directives-1.0.2.tar.gz:
Publisher:
python-publish.yml on TeachBooks/Sphinx-Gated-Directives
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinx_gated_directives-1.0.2.tar.gz -
Subject digest:
16df805c76e4620b5c28e13d1c33ea72d3bbe9d2f3651819ec410b0031651537 - Sigstore transparency entry: 795069761
- Sigstore integration time:
-
Permalink:
TeachBooks/Sphinx-Gated-Directives@07cf8dab818335a82cbf6f5f14a61c21af411a5e -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/TeachBooks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@07cf8dab818335a82cbf6f5f14a61c21af411a5e -
Trigger Event:
push
-
Statement type:
File details
Details for the file sphinx_gated_directives-1.0.2-py3-none-any.whl.
File metadata
- Download URL: sphinx_gated_directives-1.0.2-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a3f55e7d1b3c2086f432f2b82dab0fbbe6b3012e22f661f1c16c6b9c1c7c0a7
|
|
| MD5 |
1a6910ae4e4b0587a55b811de168658c
|
|
| BLAKE2b-256 |
4e705263992122855b3eb152a789f7ff5322aaf2f92425df59dc1175a8b935cc
|
Provenance
The following attestation bundles were made for sphinx_gated_directives-1.0.2-py3-none-any.whl:
Publisher:
python-publish.yml on TeachBooks/Sphinx-Gated-Directives
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinx_gated_directives-1.0.2-py3-none-any.whl -
Subject digest:
3a3f55e7d1b3c2086f432f2b82dab0fbbe6b3012e22f661f1c16c6b9c1c7c0a7 - Sigstore transparency entry: 795069892
- Sigstore integration time:
-
Permalink:
TeachBooks/Sphinx-Gated-Directives@07cf8dab818335a82cbf6f5f14a61c21af411a5e -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/TeachBooks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@07cf8dab818335a82cbf6f5f14a61c21af411a5e -
Trigger Event:
push
-
Statement type: