From d1f509a90fb0d17527aa564b1ed298ccc06651a4 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 24 Dec 2021 23:13:23 -0800 Subject: [PATCH] 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. --- 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;