3

I'm working on theming my documentation, and I'm trying to get sphinx to add a class to the <ul> elements of the Table of Contents. Unfortunately, it looks like the HTML is generated just the same as any other list.

Is there a way to add a class to the TOC?

The class that I want to add (fyi) is nav nav-tabs nav-stacked; I'm using a bootstrap theme.

Update: my current hack is to override localtoc.html template to have

{{ toc|replace("<ul>", "<ul class='nav nav-tabs nav-stacked'>") }}

but it feels ugly...

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Jared Forsyth
  • 12,808
  • 7
  • 45
  • 54

1 Answers1

1

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.

devin_s
  • 3,345
  • 1
  • 27
  • 32