문제

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