Modify Sphinx TOC tree

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

I have a Sphinx project with a TOC (index.rst) that includes :maxdepth: 2. The problem is I want to reduce the depth to 1 for the release section so that it doesn't include the list of release notes in the main TOC (the list is too long).

It seems that the TOC list can be modified using a doctree-resolved event handler, but I can't figure out how to modify the TOC tree in the event handler:

from sphinx import addnodes  def setup(app):     def update_toctree(app, doctree, docname):         if docname != 'index':             return          node = doctree.traverse(addnodes.toctree)[0]         toc = app.env.resolve_toctree(docname, app.builder, node)          # do something with "toc" here      app.connect('doctree-resolved', update_toctree)

回答1:

Perhaps not an ideal solution, but I've done something like this before using multiple toctree entries on the same page, something like:

#################### Presto Documentation ####################  .. toctree::     :maxdepth: 2      overview     installation  .. toctree::     :maxdepth: 1      release

It's not ideal since most themes will add extra padding between the trees, but in my case that was better than having the huge list of nested items for certain pages.



回答2:

I found a low-tech solution: hide the children of the last item using CSS.

div.toctree-wrapper > ul > li:last-child > ul {   display: none; }


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