So essentially I am trying to replicate the functionality of the collapsible tree in the sidebar of websites like the documentation for unity and unreal.
http://docs.unity3d.com/Manual/index.html Basically as I see it the hierarchal collapsing tree in the sidebar is just a TocTree. I've already started writing an extension for my project, and currently it creates a global TocTree in the sidebar that links relative to the current page. The final steps should be to make the individual elements in the tree be collapsible, then define the ascending and descending depth from the current page that should defined the uncollapsed range. I've seen a few approaches to doing similar functionality but I am not sure which is best. Currently I am adding the sidebar TocTree in response to the "builder-init" event. Based off another extension that exists in my project for collapsible and tabbed code blocks. I created the html content to be injected into the nodes to make them collapsible. After a lot of research and frustration going through various Sphinx documentation I found the NodeVisitor class which I think I can use to do what I need to do to the TocTrees I am building to make them collapsible. Unfortunately there is a *args parameter for the NodeVisitor constructor. I can not find any documentation on what type of object this is supposed to be. I am getting a error saying "NoneType does not have attribute Reporter" which I can not find documentation for either. If any further info is needed let me know. I hoped someone can help! -- You received this message because you are subscribed to the Google Groups "sphinx-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sphinx-users. For more options, visit https://groups.google.com/d/optout.
toctree
{{ local_toctree(pathto(pagename), master_doc, pagename, maxdepth=-1) }}
# -*- coding: utf-8 -*-
from docutils import nodes
from sphinx import addnodes
import os.path
"""
``local_toctree``: A callable yielding the global TOC tree that contains
list of all the content below the specified page. ``local_toctree`` need
pagename specifing as like as ``{{ local_toctree(pagename) }}`` and
optional keyword arguments are available:
* maxdepth (defaults to the max depth selected in the toctree directive):
the maximum depth of the tree; set it to -1 to allow unlimited depth
"""
class collapsibleNodeVisitor(nodes.NodeVisitor):
def visit(self, node):
#Make a link where the directive was encountered, that opens/closes its matching div
self.body.append(u'<a class="collapsibleToc" href="#!" id="%slink"' % node.options['divID'] + u'>%s</a><br>' % node.options['divToggleLinkText'])
#Start collapsible div
self.body.append(u'<div id="%s" class="collapsibleTocArea"' % node.options['divID'] + u' style="display:none;">')
def depart(self, node):
#After processing all the contents, close the collapsible div
self.body.append(u'</div>')
def init_local_toctree(app):
def _get_local_toctree(pagePath, masterDoc, docname, **kwds):
indexDocTree = app.env.get_doctree(masterDoc)
#debugOut = open('debugOut', 'a')
#debugOut.write('\n')
#debugOut.write("Current Doc")
#debugOut.write('\n')
#debugOut.write(docname)
#debugOut.write('\n')
#debugOut.write(pagePath)
#debugOut.write('\n')
if(docname == "genindex" or docname == "search"):
#debugOut.write("file does not exist")
return None
# .write("file exists")
doctree = app.env.get_doctree(docname)
if 'maxdepth' not in kwds:
kwds['maxdepth'] = 0
kwds['collapse'] = False
kwds['includehidden'] = True
toctrees = []
for toctreenode in indexDocTree.traverse(addnodes.toctree):
toctree = app.env.resolve_toctree(
docname, app.builder, toctreenode, **kwds)
toctrees.append(toctree)
if not toctrees:
#debugOut.close()
return None
result = toctrees[0]
for toctree in toctrees[1:]:
if not toctree:
continue
result.extend(toctree.children)
result.walkabout(collapsibleNodeVisitor("collapsibleToc"))
#debugOut.close()
renderedToc = app.builder.render_partial(result)['fragment']
return renderedToc
ctx = app.env.config['html_context']
if 'local_toctree' not in ctx:
ctx['local_toctree'] = _get_local_toctree
#def on_html_page_context(app, pagename, templatename, context, doctree)
def setup(app):
#This actually builds the sidebar global toctree with relative links
app.connect('builder-inited', init_local_toctree)
#app.connect('html-page-context', on_html_page_context)
#Add node for parsing, allow us to call visit/depart function when using
#An HTML writer
#app.add_node(collapsibleToc, html=(visit_collapsible_toc, depart_collapsible_toc))
