Overriding toctree() function

78 views
Skip to first unread message

Kevin Sheppard

unread,
Aug 19, 2019, 11:44:04 AM8/19/19
to sphinx-users
Is it possible to override the toctree() function that is used in globaltoc.html.  I am trying to use a format that I can't sequeeze out of the ul/li that toctree() generates.  

Thanks,
Kevin

Kay Mccormick

unread,
Aug 19, 2019, 11:47:51 AM8/19/19
to sphinx...@googlegroups.com
The toctree infrastructure is due for a refactor. It'd be great to see what we can do with this functionality and if there are opportunities to push some of it upstream to docutils core.

I've done extensive work on customizing toctree's in various ways. I can dig up some code for this.

Kay

--
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 sphinx-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/44dac177-8ee9-47cd-9b60-9b0de4088f21%40googlegroups.com.

Kevin Sheppard

unread,
Aug 19, 2019, 11:59:26 AM8/19/19
to sphinx-users
Thanks, that would be helpful.  It would be great if the entries were available to be directly templated.  I did some more poking around and it looks like some of the code pretty deep  in TocTree.


On Monday, August 19, 2019 at 4:47:51 PM UTC+1, Kay Mccormick wrote:
The toctree infrastructure is due for a refactor. It'd be great to see what we can do with this functionality and if there are opportunities to push some of it upstream to docutils core.

I've done extensive work on customizing toctree's in various ways. I can dig up some code for this.

Kay

On Mon, Aug 19, 2019 at 8:44 AM Kevin Sheppard <kevin.k...@gmail.com> wrote:
Is it possible to override the toctree() function that is used in globaltoc.html.  I am trying to use a format that I can't sequeeze out of the ul/li that toctree() generates.  

Thanks,
Kevin

--
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 sphinx...@googlegroups.com.

Kay Mccormick

unread,
Aug 20, 2019, 12:20:50 PM8/20/19
to sphinx...@googlegroups.com
The code is here:


It's not ready for primetime - it only works for the XML builder, and is designed to generate XLink-based references. But it can be adapted. I'm playing around with it right now and trying to figure it out.

Take a look at build_finished.

    master_doc = app.config.master_doc
    toctree = TocTree(app.env).get_toctree_for(master_doc, app.builder, False)
    if toctree:
        visitor = TocVisitor(document, app.builder, app.config.master_doc)
        visitor.new['master'] = True
        toctree.walkabout(visitor)
        document.children.append(visitor.new)
    
this code builds the toc tree, transforms it (not in place) and then places it into a new document ('_links'). It isn't what you want but could give you a head start.

Kevin Sheppard

unread,
Aug 21, 2019, 6:46:03 PM8/21/19
to sphinx-users
Thanks for this.  It may take me a while to figure it all out.  As a sort term fix, I noticed that I can inject template function through html_context which allows me to break down the toc and toctree and then to rebuild them the way I want. This route is definitely more fragile than generating the toc directly.
Reply all
Reply to author
Forward
0 new messages