Tuomas Räsänen 写道:
Hi Tuomas,
> Well, if I understood you correctly, I needed something similiar and
> ended up with this small extension:
>
> toctree_items = []
>
> def html_page_context(app, pagename, templatename, context, doctree):
> context['toctree_items'] = toctree_items
>
> def env_updated(app, env):
> master_doc = app.builder.config.master_doc
> toctree = env.tocs[master_doc].traverse(lambda n: n.tagname ==
> 'toctree')[0]
> global toctree_items
> for link_label, pagename in toctree['entries']:
> if pagename == 'self':
> pagename = master_doc
> pagetitle = env.toctree_items[pagename].astext()
> toctree_items.insert(0, (pagename, pagetitle))
>
> def setup(app):
> app.connect('html-page-context', html_page_context)
> app.connect('env-updated', env_updated)
>
>
> I didn't want the toctree to be included as <ul> in the html-output but
> I still needed that same info to generate navigation bars.
>
> So I defined my toctrees to be hidden:
>
> .. toctree::
> :hidden:
>
> And then dug the toctee information on 'env-updated' event (after all
> nodes has been resolved) and passed that to template as a part of it's
> context. I hope this helps a bit. That snippet isn't probably the best
> way to do it, but I'm still quite newbie with Sphinx. :)
>
Thanks, but I cannot understand your code. Why is there no thing like
'visit_toctree'?
I looked into sources of latex.py, html.py, and text.py in both builders/ and
writers/.
There is also rarely anything like visit_toctree. Does it mean toctree cannot be
handled as a node? I also tried to manipulate toctree with visit_ like other
nodes,
but it is ignored. Here is my code:
def visit_toctree(self, node):
node['maxdepth'] = 1
self.body.append('anywords')
I'm a newbie with Sphinx too. It's hard for me to get Sphinx's logic.
Best wishes,
Wei-Wei
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sphinx-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sphinx-dev?hl=en
-~----------~----~----~----~------~----~------~--~---