Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a custom HTML div in Sphinx that isn't automatically nested within a subsubsection?

I'm using the wonderful Sphinx tool to create some documentation and I need to create a custom HTML div so that I can style it apart from Sphinx's other, automatically-created, divs.

This is possible to do using the container directive, but the problem is that if I use this directive below a subsubsection, it automatically nests the div created with the container directive within the subsubsection, like so:

<div id="automatically-created sphinx subsubsection">
   ...
   <div id="my custom container"></div>
</div>

Whereas, I want:

<div id="automatically-created sphinx subsubsection">
   ...
</div>
<div id="my custom container"></div>

Is there any way to do this? Any help would be greatly appreciated!

Addendum:

One hacky way of potentially solving the problem is to create a new subsubsection so that Sphinx automatically places it on the same level as other subsubsections and then use CSS to hide its header etc. The problem with this approach, however, is that the new subsubsection automatically gets added to the sidebar in the RTD theme (which I'm using) and this is not what I want.

like image 655
AZD Avatar asked Oct 28 '25 04:10

AZD


1 Answers

Untested. Try a super-hacky .. raw:: directive, where you would close the current section, then open a new unclosed <div>:

.. raw:: html

    </div>
    <div id="my custom container">

Then resume using reStructured text markup. This would "trick" Sphinx into thinking that the current section is still open and it would still add a closing </div> after the rest of your markup until it starts parsing the next section.

like image 186
Steve Piercy Avatar answered Oct 30 '25 13:10

Steve Piercy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!