修改狮身人面像目录

2024-04-26 01:29:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个包含:maxdepth: 2的TOC(index.rst)的Sphinx project。问题是我想将release部分的深度减少到1,这样它就不会在主目录中包含发行说明列表(列表太长)。在

似乎可以使用doctree-resolved事件处理程序修改TOC列表,但我无法确定如何在事件处理程序中修改TOC树:

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)

Tags: nodeapp处理程序列表indexdef事件update
2条回答

我找到了一个低技术的解决方案:使用CSS隐藏最后一项的子项。在

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

也许不是一个理想的解决方案,但是在同一页面上使用多个toctree项之前,我做过类似的事情,比如:

####################
Presto Documentation
####################

.. toctree::
    :maxdepth: 2

    overview
    installation

.. toctree::
    :maxdepth: 1

    release

这并不理想,因为大多数主题都会在树之间添加额外的填充,但在我的例子中,这比为某些页面提供大量嵌套项要好。在

相关问题 更多 >