提供用于渲染RunThis块的sphinx代码块
项目描述
runthis-sphinxext
这提供了一个sphinx扩展,它添加了RunThis代码块,这些代码块静态显示高亮的代码块,但在它们上方有一个“RunThis”按钮。当按钮被点击时,代码块将被替换为执行了该代码的终端会话。
安装
RunThis Sphinx扩展可以使用conda或pip进行安装
# use the conda-forge channel
$ conda install -c conda-forge runthis-sphinxext
# Or you can use Pip, if you must.
$ pip install runthis-sphinxext
配置
要使用RunThis代码块,您必须配置sphinx以了解RunThis。首先,确保sphinx扩展已注册。在conf.py
中,在扩展块中添加runthis.sphinxext
extensions = [
...
"runthis.sphinxext",
...
]
之后,您还需要告诉sphinxRunThis服务器所在的位置。这可以通过conf.py
中的runthis_server
变量设置。例如
# runthis options
runthis_server = "http://localhost:5000"
使用RunThis指令与rST中的code-block
指令非常相似。在您的任何*.rst
文件中,您可以使用runthis
指令,后跟同一行的语言名称。在任何code-block
选项和一行或多行空白之后,您想要显示和运行的代码位于缩进块中。例如
这将使用conf.py
文件中指定的远程服务器执行。
.. runthis:: python
import sys
print(sys.executable)
项目详情