Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 75ff8e6

Browse filesBrowse files
Trotttargos
authored andcommitted
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: #41318 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
1 parent 5cfc547 commit 75ff8e6
Copy full SHA for 75ff8e6

File tree

Expand file treeCollapse file tree

1 file changed

+6
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-2
lines changed
Open diff view settings
Collapse file

‎tools/doc/html.mjs‎

Copy file name to clipboardExpand all lines: tools/doc/html.mjs
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,14 @@ function processContent(content) {
7373
}
7474
// `++level` to convert the string to a number and increment it.
7575
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.
7781
let firstTime = true;
7882
return content
79-
.replace(/<h3/g, (heading) => {
83+
.replace(/(?<!<section [^>]+>)<h3/g, (heading) => {
8084
if (firstTime) {
8185
firstTime = false;
8286
return '<section>' + heading;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.