From 75ff8e6505fe5b52e3f7ad894f82d9ad5922688b Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 27 Dec 2021 12:13:22 -0800 Subject: [PATCH] tools: improve section tag additions in HTML doc generator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Tobias Nießen Reviewed-By: Mohammed Keyvanzadeh --- tools/doc/html.mjs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/doc/html.mjs b/tools/doc/html.mjs index 34431ad9d829b2..8d356836eb5667 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(/

{ + .replace(/(?]+>)

{ if (firstTime) { firstTime = false; return '
' + heading;