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

此生再无相见时 提交于 2020-02-02 10:14:11

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/46053005/how-to-create-a-custom-html-div-in-sphinx-that-isnt-automatically-nested-within

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!