GeezerVison is showing github.com — tools: improve section tag additions in HTML doc generator · nodejs/node@75ff8e6
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: tools/doc/html.mjs +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -73,10 +73,14 @@ function processContent(content) { |
73 | 73 | } |
74 | 74 | // `++level` to convert the string to a number and increment it. |
75 | 75 | 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. |
77 | 81 | let firstTime = true; |
78 | 82 | return content |
79 | | - .replace(/<h3/g, (heading) => { |
| 83 | + .replace(/(?<!<section [^>]+>)<h3/g, (heading) => { |
80 | 84 | if (firstTime) { |
81 | 85 | firstTime = false; |
82 | 86 | return '<section>' + heading; |
|