mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
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>
This commit is contained in:
1 parent
1c0c140ae5
commit
1d2e676f8d
1 file changed
+6
-2
+6
-2
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user