小编Bud*_*ger的帖子

如何在Sphinx中创建全局角色/角色?

这是"ReST Strikethrough" ReST删除的后续行动,但是在Sphinx而不是ReST背景下.我的问题是,在sphinx中是否有一个中心位置放置一个"角色"指令,或者这个指令是否真的必须在sphinx docmentation中的每个第一个文件中重复.

更详细:

使用角色指令很容易为内联文本定义自定义CSS样式(请参阅ReST Strikethrough作为示例):

.. role:: custom
   :class: custom

This is an :custom:`inline text`.
Run Code Online (Sandbox Code Playgroud)

转换为html渲染

.. This is an <span class="custom">inline text</span>.  ..
Run Code Online (Sandbox Code Playgroud)

此外,可以轻松地将自定义样式表添加到sphinx(请参阅http://www.tinkerer.me/doc/theming.html),在其中添加CSS类选择器以控制"自定义"文本的呈现方式(颜色,删除线,字体大小...)

令我不安的是,在我的实验中,我不得不在每个使用自定义角色的ReST文件中重复角色指令.是否有一个"中心"的地方,我可以为整个网站定义一次?

restructuredtext python-sphinx

19
推荐指数
2
解决办法
5579
查看次数

如何在conf.py中为sphinx设置自定义配置值?(例如,对于sphinx.ext.ifconfig)

[经过更多的测试和研究后,我把原来的问题分成了两个]

我在conf.py中定义了自己的配置值,并编写了一个最小扩展名,以便从第一个文件中看到它.

在conf.py中:

sys.path.insert(0, os.path.abspath('.'))
extensions = ['sphinx.ext.ifconfig', 'myExt']
testlevel = 2
Run Code Online (Sandbox Code Playgroud)

在本地myExt.py中:

def setup(app):
   app.add_config_value('testlevel', '', True)
Run Code Online (Sandbox Code Playgroud)

这很好用; test.rst包括:

.. ifconfig:: testlevel == 2

    Hurray, it seems to work
Run Code Online (Sandbox Code Playgroud)

根据sphinx.ext.ifconfig的文档,似乎可以直接从conf.py调用*app.add_config_value*.谁能告诉我怎么做?

python-sphinx

5
推荐指数
1
解决办法
2534
查看次数

标签 统计

python-sphinx ×2

restructuredtext ×1