Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: improve section tag additions in HTML doc generator #41318

Merged
merged 1 commit into from Dec 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions tools/doc/html.mjs
Expand Up @@ -73,10 +73,14 @@ function processContent(content) {
}
// `++level` to convert the string to a number and increment it.
content = content.replace(/(?<=<\/?h)[1-5](?=[^<>]*>)/g, (level) => ++level);
// Wrap h3 tags in section tags.
// Wrap h3 tags in section tags unless they are immediately preceded by a
// section tag. The latter happens when GFM footnotes are generated. We don't
// want to add another section tag to the footnotes section at the end of the
// document because that will result in an empty section element. While not an
// HTML error, it's enough for validator.w3.org to print a warning.
let firstTime = true;
return content
.replace(/<h3/g, (heading) => {
.replace(/(?<!<section [^>]+>)<h3/g, (heading) => {
if (firstTime) {
firstTime = false;
return '<section>' + heading;
Expand Down