sphinx_rtd_theme icon indicating copy to clipboard operation
sphinx_rtd_theme copied to clipboard

Unequal number of <div> and </div> in sphinx_rtd_theme/layout.html

Open thomas-nilsson-irfu opened this issue 3 years ago • 6 comments

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).

thomas-nilsson-irfu avatar Jan 10 '22 10:01 thomas-nilsson-irfu

Hey @thomas-nilsson-irfu I want to resolve this error. Can I?

NaincyKumariKnoldus avatar Jan 10 '22 10:01 NaincyKumariKnoldus

Hi @NaincyKumariKnoldus ! Your contribution is more than welcome. We haven't yet assessed what <div> is missing a closing tag.

astrojuanlu avatar Jan 10 '22 11:01 astrojuanlu

hye @astrojuanlu I will see that which

is missing closing tag. Can I?

NaincyKumariKnoldus avatar Jan 10 '22 11:01 NaincyKumariKnoldus

Hello @astrojuanlu and @thomas-nilsson-irfu I have raised now a PR for this and fixed this issue. Please review it. Thanks!

NaincyKumariKnoldus avatar Jan 10 '22 12:01 NaincyKumariKnoldus

xref #1274

astrojuanlu avatar Jan 11 '22 12:01 astrojuanlu

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.

Screenshot 2022-06-09 at 14 19 10

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 🫠

tombai777 avatar Jun 09 '22 13:06 tombai777