Skip to content

Commit 75ff8e6

Browse files
Trotttargos
authored andcommitted
tools: improve section tag additions in HTML doc generator
There is an edge case involving GFM footnotes where our current code adds an empty section which results in a warning (but not an error) in HTML validators. This change causes the HTML generator to skip the unnecessary addition of a section tag in that one edge case. PR-URL: #41318 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
1 parent 5cfc547 commit 75ff8e6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tools/doc/html.mjs

+6-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,14 @@ function processContent(content) {
7373
}
7474
// `++level` to convert the string to a number and increment it.
7575
content = content.replace(/(?<=<\/?h)[1-5](?=[^<>]*>)/g, (level) => ++level);
76-
// Wrap h3 tags in section tags.
76+
// Wrap h3 tags in section tags unless they are immediately preceded by a
77+
// section tag. The latter happens when GFM footnotes are generated. We don't
78+
// want to add another section tag to the footnotes section at the end of the
79+
// document because that will result in an empty section element. While not an
80+
// HTML error, it's enough for validator.w3.org to print a warning.
7781
let firstTime = true;
7882
return content
79-
.replace(/<h3/g, (heading) => {
83+
.replace(/(?<!<section [^>]+>)<h3/g, (heading) => {
8084
if (firstTime) {
8185
firstTime = false;
8286
return '<section>' + heading;

0 commit comments

Comments
 (0)