The TOCs are converted to HTML separately and then inserted into the document, without letting you control it. Checkout the render_partial
method of sphinx.builds.html.StandaloneHTMLBuilder
.
Your hack is the easiest method, the other option is to subclass StandaloneHTMLBuilder
and override render_partial
to control the docutils' HTMLWriter
.