过去,我需要能够从同一个源文件编译两个文档:公共文档和私有文档。
为了成功,我必须编写自己的插件(你可以找到here https://gist.github.com/kakawait/9215487).
当我的文件仅包含在私人文档中时,我只需在文件顶部添加以下指令(强制)
.. meta::
:scope: private_version
public-sample.rst(没什么特别的)
Title
=====
A public content
私人样本.rst
.. meta::
:scope: private_version
Title
=====
A private content
索引.rst
.. toctree::
:maxdepth: 3
public-sample.rst
private-sample.rst
正如你所看到的toctree
有两个参考,但插件将删除私人样本.rst在编译期间如果您没有使用标签构建private
So using
sphinx-build ... -t private_version ...
会生成toctree
like:
但如果你用
sphinx-build ... -t other ...
or
sphinx-build ...
the toctree
看起来像
我的插件不是 100% 完美,但我只是一小段易于理解的代码,因此您可以根据需要进行编辑:)
了解限制:
局限性:
- 指令 .. meta:: :scope: 必须放在文件顶部(之前没有行)
- 指令 .. meta:: :scope: 必须与正则表达式 ^.. meta::\s+:scope: ([a-zA-Z0-9_-]+) 匹配
- 指令 .. meta:: :scope: 可以管理多个标签,但您可以根据需要轻松更新插件
- 插件偏离了原来的用途
meta
指令 docutils.sourceforge.net/docs/ref/rst/directives.html#meta