Open latosha-maltba opened 3 years ago
What theme are you using?
All themes derived from basic
should be fine, because this is handled:
For example: https://insipid-sphinx-theme.readthedocs.io/en/0.2.3/showcase/sections.html#local-table-of-contents
I encountered this in multiple themes. For a more systematic approach I looked at the themes provided by sphinx-themes.org. Sadly, the .. content:: directive does not render anything (bug pending). However, I found a list with "simple" in the admonitions and compared those to the list generated by .. toctree::
In total there were 113 themes, 41 showed a different style for the lists (probably because of the <p>
but I have not verified that). At least some (possibly all) of these themes do not include basic.css.
About 23 themes showed different spacing for the second level. I classified those as "possibly flawed" but have not investigated the source of the problem.
So about 40% of themes might be affected.
The docutils; a base library of reStructuredText has started to generate <p>
tags for each paragraph on generating HTML5 (At HTML4 era, neadless <p>
tags are suppressed). Therefore, the contents
directive generates them now. On the other hand, the toctree
directive is a custom directive of Sphinx, not a reST standard one. It does not generate <p>
tags even after the HTML5 era. I think toctree
directive should be fixed as the contents
directive does.
Sounds reasonable although I still wonder whether using <p>
inside a toc list is (philosophically) the correct usage of a paragraph element. Nevertheless, I'll consider unifying the HTML-tree of those directives (either at docutils' end or at sphinx's end) more important than having a philosophical dispute. :-)
.. toctree::
and.. contents::
generate different DOM structure with the HTML builder. More precisely,.. contents::
wraps its list elements in paragraphs while.. doctree::
does not. Compare:For
.. toctree::
For
.. contents::
(Note the additional
<p>
.)A consequence of this is for example that themes which style paragraphs to have gaps between them (e.g. via margins), have large gaps in the contents TOC. Since
.. contents::
is a table of contents and its elements are the headlines, it seems more appropriate to not wrap the header in an paragraph tag. I did not test other builders (which might exhibit similar behaviour) and did not investigate what the internal AST/doctree representation of these two constructs is.Tested with Sphinx 3.3.1 and current HEAD (633c5ad9c6f4511e3016dd451f17ace1ad160fb2 as of this writing).
Minimal working example: