2015-11-10 40 views
8

我有一個Sphinx project用TOC(index.rst),包括:maxdepth: 2。問題是我想深度減少1release部分,因此它不包括在主TOC(名單太長)發行說明列表。修改獅身人面像TOC樹

看來,TOC列表可以使用doctree-resolved事件處理程序進行修改,但我無法弄清楚如何修改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) 
+0

與您遇到同樣的問題 - 我能夠讀取和修改TOC節點,但似乎無法持續更改。 – geographika

回答

1

我發現了一個低技術含量的解決方案:隱藏使用CSS的最後一個項目的孩子們。

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

也許不是一個理想的解決方案,但我已經做了一些類似這樣使用多toctree條目在同一頁上,像前:

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

.. toctree:: 
    :maxdepth: 2 

    overview 
    installation 

.. toctree:: 
    :maxdepth: 1 

    release 

這不是理想的,因爲大多數主題將添加在樹木間微胖,但對我來說,這是優於有e特定頁面的嵌套項目的巨大列表。

+0

這是一個有趣的解決方案,但它並不在我的情況下提供幫助,因爲我們使用「編號」,所以開始一個新的TOC將重新編號。 –