Sphinx Prompt is a Sphinx directive that allows developers to add code blocks with unselectable prompts to their documentation. This ensures that readers can easily copy and paste commands without including the prompt characters. The library is actively maintained, with frequent minor releases, and is currently at version 1.10.2.
pip install sphinx-promptVerified import paths — ran on the pinned version, not inferred.
After installing the library and adding 'sphinx_prompt' to your `conf.py` extensions, you can use the `.. prompt::` directive in your reStructuredText files. You can specify a language (e.g., `python`, `bash`, `powershell`) and a custom prompt. If no prompt is given for a shell language, a default is used (e.g., `$` for bash, `C:\>` for batch, `PS C:\>` for powershell).
Ensure your Sphinx installation is compatible with `sphinx-prompt`. For `sphinx-prompt` 1.9.0+, consider upgrading Sphinx to version 8 or later. For older Sphinx versions, use an earlier `sphinx-prompt` release.
Upgrade your Python environment to 3.11 or newer if you wish to use `sphinx-prompt` 1.10.0 or later. Alternatively, pin your `sphinx-prompt` version to an earlier release compatible with your Python version (e.g., `<1.10.0` for Python < 3.11).
Instead of `.. prompt:: bash (venv) $`, use the `:prompts:` option: `.. prompt:: bash :prompts: (venv) $`
As a general rule, ensure `sphinx_prompt` is listed *before* other extensions that might preprocess or transform code block content in your `conf.py` file to ensure `sphinx-prompt`'s directive is processed first.