sphinx-contrib / fulltoc

Extension for Sphinx to make the sidebar show a full table of contents instead of just the local headings
Apache License 2.0
38 stars 19 forks source link

Add check for toctree function, needed for json builder compatibility #11

Closed eli-collins closed 7 years ago

eli-collins commented 8 years ago

I think this change fixes issue #10 - the json builder doesn't define a toctree function, and omitting the replacement if it wasn't already set seems to build correctly.

electrofelix commented 7 years ago

If it helps this get merged you can see in the sphinx-doc/sphinx repository the code at https://github.com/sphinx-doc/sphinx/blob/70600e99818ab517585035f46d9146133a68f91a/sphinx/builders/html.py#L773-L840 is what is executed for the html builder, which contains the lines

        ctx['toctree'] = lambda **kw: self._get_local_toctree(pagename, **kw)
        self.add_sidebars(pagename, ctx)

at https://github.com/sphinx-doc/sphinx/blob/70600e99818ab517585035f46d9146133a68f91a/sphinx/builders/html.py#L809-L810

These are responsible for triggering the toc generation for the HTML pages, however for the JSON builder the handle_page method is overridden with one from the SerializingHTMLBuilder class https://github.com/sphinx-doc/sphinx/blob/70600e99818ab517585035f46d9146133a68f91a/sphinx/builders/html.py#L1124-L1146, which does not have toctree. So the fix will work for all builders based on the SerializingHTMLBuilder class.