跳转到主要内容

Sphinx的替换扩展,允许在代码块中进行替换。

项目描述

Build Status codecov PyPI

Sphinx Substitution Extensions

Sphinx的扩展,允许在代码块中进行替换。

安装

Sphinx Substitution Extensions与Python 3.10+兼容,兼容Sphinx 7.2.0+。

$ pip install Sphinx-Substitution-Extensions

rST 设置

  1. 将以下内容添加到conf.py中启用扩展

extensions += ['sphinx_substitution_extensions']
  1. conf.py中设置以下变量以定义替换

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

这将用0.1替换新指令中的|release|,并用Eleanor替换|author|

在rST文档中使用替换

代码块

这为Sphinx内置的code-block指令添加了:substitutions:选项。

.. code-block:: bash
   :substitutions:

   echo "|author| released version |release|"

内联 :substitution-code:

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

替换下载

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

MyST Markdown 设置

  1. 将以下内容添加到conf.py中启用扩展

extensions += ['sphinx_substitution_extensions']
  1. conf.py中设置以下变量以定义替换

myst_enable_extensions += ['substitution']
myst_substitutions = {
      "release": "0.1",
      "author": "Eleanor",
}

这将用0.1替换新指令中的|release|,并用Eleanor替换|author|

在MyST Markdown中使用替换

代码块

这为Sphinx内置的code-block指令添加了:substitutions:选项。

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

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

鸣谢

ClusterHQ 开发者

本软件包在很大程度上受到了ClusterHQ为Flocker编写的代码的启发。相关代码的开发者至少包括Jon Giddy和Tom Prince。

贡献

请参阅CONTRIBUTING.rst

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。

源代码分发

sphinx_substitution_extensions-2024.8.6.tar.gz (25.5 kB 查看哈希值)

上传时间 源代码

构建分发

sphinx_substitution_extensions-2024.8.6-py2.py3-none-any.whl (12.9 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下机构支持