Emit more valid HTML from rustdoc #93576
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, tidy-html5 (
tidy
) would complain about a few things in our HTML. The main thing is that<summary>
tags can't contain<div>
s. That's easily fixed by changing out the<div>
s for<span>
s withdisplay: block
.However, there's also a rule that
<span>
s can't contain heading elements.<span>
permits only "phrasing content" https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span, and<h3>
(and friends) are "Flow content, heading content, palpable content". https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_ElementsWe have a wrapping
<div>
that goes around each<h3>
/<h4>
, etc. We turn that into a<section>
rather than a<span>
because<section>
permits "flow content". https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sectionAfter this change we get only three warnings from tidy, run on struct.String.html:
line 6 column 10790 - Warning: trimming empty
line 1 column 1118 - Warning: proprietary attribute "disabled"
line 1 column 1193 - Warning: proprietary attribute "disabled"
The empty
<span>
is a known issue - there's a span in front of the search box to work around a strange Safari issue.The
<link>
attributes are the non-default stylesheets. We can probably refactor theme application to avoid using this proprietary "disabled" attribute.We can suppress those warnings with flags to tidy, and get a run that returns 0 (success):
Note: this requires the latest version of tidy-html5, built from https://github.com/htacg/tidy-html5. Older versions (including the default version on Ubuntu 21.10) think
<section>
can't occur inside<summary>
.Demo: https://rustdoc.crud.net/jsha/fix-rustdoc-html/std/string/struct.String.html
r? @GuillaumeGomez