diff options
author | Rich Trott <rtrott@gmail.com> | 2021-12-27 23:13:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-27 23:13:22 +0300 |
commit | e4aa575b05fcf560c6b77b0fa5036328a3417442 (patch) | |
tree | 834fe18d7f60eda85200ed6ebf392a281d53092e /tools | |
parent | d34fcb68c93fc918563e311e40a9b6901b906b60 (diff) |
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: https://github.com/nodejs/node/pull/41318
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/doc/html.mjs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/tools/doc/html.mjs b/tools/doc/html.mjs index 34431ad9d82..8d356836eb5 100644 --- a/tools/doc/html.mjs +++ b/tools/doc/html.mjs @@ -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; |