【发布时间】:2020-03-18 22:17:04
【问题描述】:
我正在改进一些技术文档 (Sphinx),并希望在多个位置包含 RST 文件的内容;但是,这样做会多次将该 RST 文件添加到 TOC。如何将文件包含在我想要的位置,但只在 TOC 中引用该部分一次?
下面是 index.rst 文件的样子:
Documentation
=================
.. toctree::
:maxdepth: 4
../path/to/releasenotes.rst
../path/to/general_api_usage.rst
main_content.rst
接下来,这里是 main_content.rst:
============
Main Content
============
These docs reference:
- :ref:`section-1`.
- :ref:`section-2`.
- :ref:`section-3`.
- :ref:`section-4`.
.. include:: section1.rst
.. include:: section2.rst
.. include:: section3.rst
.. include:: section4.rst
“第4节”是参考表;例如,我想将它包含在“第 2 节”中,但也像附录一样将其保留在文档的底部。
section2.rst 如下所示:
.. _section-2:
This is Section 2
********************
.. include: section4.rst
Some other Section 2 content.
最后,section4.rst 可能是什么样子:
.. _section-4:
This is Section 4
********************
+------------------+-------------------------+
| Heading | Heading 2 |
+==================+=========================+
| This is what I | want to reference |
+------------------+-------------------------+
| in other rst | files. |
+------------------+-------------------------+
当我这样做时,我的目录包含两次“第 4 节”。有什么见解吗?谢谢!
【问题讨论】:
-
是否可以从文档
section4.rst中删除部分标题,并在需要时将其移动到包含的文档中?还是实际上有比示例中显示的更多的标题? -
谢谢@sinoroc。这真的很有帮助。感谢您的建议,我完成了我希望做的事情。
标签: python-sphinx restructuredtext sections toctree