Using self to create a sitemap with toctree in sphinx seem broken?

最后都变了- 提交于 2019-12-07 07:43:26

问题


I'm updating a FAQ for a fairly big project and I would like to add an index of the questions at the top of the page, so it becomes easier for users to find what they're looking for.

The Sphinx documentation toctree article states "The special entry name self stands for the document containing the toctree directive. This is useful if you want to generate a “sitemap” from the toctree." This is what I want. The problem is that self seem broken and only includes the current documents title and not the subtitles. It works correctly when I'm in another document and references the FAQ, only in the document itself does it fail.

To demonstrate

.. toctree::
   :maxdepth: 3

   faq

In other file results in

  • Frequently Asked Questions
    • FAQ
      • Question 1
      • Question 2
      • Question 3
    • Non-obvious behaviour and other need to know

Inside faq

.. toctree::
   :maxdepth: 3

   self

results in

  • Frequently Asked Questions

I've thought that maybe it was because sphinx wasn't aware of the subtitles when the toctree is converted and tried moving the toctree to the bottom of the page. No change.

Any ideas on how to include a index of a page in the page itself with sphinx would be greatly appreciated


回答1:


What your are looking for is the contents directive.

Insert the following block after the title of your page to build the list of questions :

.. contents::
   :local:
   :depth: 1

It will produce:

  • Question 1
  • Question 2
  • Question 3


来源:https://stackoverflow.com/questions/16126747/using-self-to-create-a-sitemap-with-toctree-in-sphinx-seem-broken

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!