sphinx_rtd_theme
sphinx_rtd_theme copied to clipboard
Unequal number of <div> and </div> in sphinx_rtd_theme/layout.html
Problem
The included template, sphinx_rtd_theme/layout.html, does not have an equal number of <div>
and </div>
tags making it effectively invalid as per html standard.
Counting the numbers of <div>
tags I get 12 and counting </div>
I only get 11...
Reproducible Project
Including a simple shell script example:
# number of start tags:
grep -c '<div' sphinx_rtd_theme/layout.html
# number of end tags:
grep -c '</div' sphinx_rtd_theme/layout.html
Expected Results
Correctly start (<div>
) and end (</div>
) all tags in the template so it correctly follows the HTML standard, neither tag is omissible.
Ref: https://html.spec.whatwg.org/multipage/grouping-content.html#the-div-element
Environment Info
- Python Version: N/A
- Sphinx Version: N/A
- RTD Theme Version: master branch (as of 2022-01-10).
Hey @thomas-nilsson-irfu I want to resolve this error. Can I?
Hi @NaincyKumariKnoldus ! Your contribution is more than welcome. We haven't yet assessed what <div>
is missing a closing tag.
hye @astrojuanlu I will see that which
Hello @astrojuanlu and @thomas-nilsson-irfu I have raised now a PR for this and fixed this issue. Please review it. Thanks!
xref #1274
There's only an unequal number due to this conditionally templated div, so on a grep you'd get 12 of '<div'
but only 11 of 'div>'
even though it would always render correctly.

If this really is a problem you could fix it by conditionally displaying the class, roughly like this:
<div {% if theme_style_external_links|tobool %} class="rst-content style-external-links" {% else %} class="rst-content" {% endif %}>...</div>
or something similar instead of this if/else/endif block.
Could also do it with a helper function; see https://forums.meteor.com/t/solved-conditional-css-class-applied-to-element-in-template-can-this-be-simplified/7627
Not sure if this is really worth a fix (given it probably violates code style) or just to close this issue 🫠