Dear Takayuki SHIMIZUKAWA,
I'm re-making my basic sphinx template. And now I'm using your snippet.
Thank you so much. The only modification I made is removing <ul><li> which
wrap the localtoc:
# -*- coding: utf-8 -*-"""``localtoc``: A callable yielding the local TOC tree
that containslist of all headings in the specified page exclude page
title.``localtoc`` need pagename specifing like ``{{ localtoc(pagename) }}``."""
def init_localtoc(app):
def _get_localtoc(docname):
toc = app.env.get_toc_for(docname, app.builder)
try:
del toc[0][0]
return app.builder.render_partial(toc)['fragment'][9:-12] # HERE
except:
return ''
ctx = app.env.config['html_context']
if 'localtoc' not in ctx:
ctx['localtoc'] = _get_localtoc
def setup(app):
app.connect('builder-inited', init_localtoc)
I grow tired of post-processing sphinx generated htmls, and you solution
solves the issue wonderfully.
On Tuesday, January 7, 2014 at 7:14:11 PM UTC+4, Takayuki SHIMIZUKAWA wrote:
>
> Hi Boris,
>
> If you want to pass some variables/functions to jinja2 template,
> ``html_context`` conf.py setting will help you.
> However, the ``localtoc`` class is a directive that only works with reST
> source.
>
> So, I made a little extension to render headings in the page exclude a
> page title.
> https://gist.github.com/shimizukawa/8300704
> Please try it.
>
> Regards,
> --
> Takayuki SHIMIZUKAWA
> http://about.me/shimizukawa
>
--
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.