سؤال

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...

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top