Skip to content

Commit c12cbf2

Browse files
Trotttargos
authored andcommitted
tools: avoid generating duplicate id attributes
In all.html, we currently generate hundreds of duplicate id attributes because of conflicts between the way allhtml.mjs prefixes in-page links with the module name on the one hand, and the existence of legacy id attributes hardcoded into the page on the other hand. This prefaces the module name with `all_` to avoid the conflicts. PR-URL: #41291 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 23f97ec commit c12cbf2

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tools/doc/allhtml.mjs

+7-7
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,32 @@ for (const link of toc.match(/<a.*?>/g)) {
3838
.replace(/[\s\S]*?id="toc"[^>]*>\s*<\w+>.*?<\/\w+>\s*(<ul>\s*)?/, '')
3939
// Prefix TOC links with current module name
4040
.replace(/<a href="#(?!DEP[0-9]{4})([^"]+)"/g, (match, anchor) => {
41-
return `<a href="#${moduleName}_${anchor}"`;
41+
return `<a href="#all_${moduleName}_${anchor}"`;
4242
});
4343

4444
apicontent += '<section>' + data.slice(match.index + match[0].length)
4545
.replace(/<!-- API END -->[\s\S]*/, '</section>')
4646
// Prefix all in-page anchor marks with module name
4747
.replace(/<a class="mark" href="#([^"]+)" id="([^"]+)"/g, (match, anchor, id) => {
4848
if (anchor !== id) throw new Error(`Mark does not match: ${anchor} should match ${id}`);
49-
return `<a class="mark" href="#${moduleName}_${anchor}" id="${moduleName}_${anchor}"`;
49+
return `<a class="mark" href="#all_${moduleName}_${anchor}" id="all_${moduleName}_${anchor}"`;
5050
})
5151
// Prefix all in-page links with current module name
5252
.replace(/<a href="#(?!DEP[0-9]{4})([^"]+)"/g, (match, anchor) => {
53-
return `<a href="#${moduleName}_${anchor}"`;
53+
return `<a href="#all_${moduleName}_${anchor}"`;
5454
})
5555
// Update footnote id attributes on anchors
5656
.replace(/<a href="([^"]+)" id="(user-content-fn[^"]+)"/g, (match, href, id) => {
57-
return `<a href="${href}" id="${moduleName}_${id}"`;
57+
return `<a href="${href}" id="all_${moduleName}_${id}"`;
5858
})
5959
// Update footnote id attributes on list items
60-
.replace(/<(\S+) id="(user-content-fn-\d+)"/g, (match, tagName, id) => {
61-
return `<${tagName} id="${moduleName}_${id}"`;
60+
.replace(/<(\S+) id="(user-content-fn[^"]+)"/g, (match, tagName, id) => {
61+
return `<${tagName} id="all_${moduleName}_${id}"`;
6262
})
6363
// Prefix all links to other docs modules with those module names
6464
.replace(/<a href="((\w[^#"]*)\.html)#/g, (match, href, linkModule) => {
6565
if (!htmlFiles.includes(href)) return match;
66-
return `<a href="#${linkModule}_`;
66+
return `<a href="#all_${linkModule}_`;
6767
})
6868
.trim() + '\n';
6969

0 commit comments

Comments
 (0)