我正在改进一些技术文档(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节”。有什么见解吗?谢谢!
发布于 2019-11-23 05:38:13
感谢@sinoroc的一个建议,我想出了一个解决方案:
我从section4.rst中删除了以下内容,只保留了表:
.. _section-4:
This is Section 4
********************我将其添加到新文件appendix.rst的顶部,并添加了对section4.rst的引用:
.. _section-4:
This is Section 4
********************
.. include:: section4.rst然后我修改了我的main_content.rst以引用appendix.rst而不是section4.rst。
我的主要学习要点: TOC反映了引用文件中的标题。
https://stackoverflow.com/questions/59001062
复制相似问题