Skip to content

Commit

Permalink
tools: avoid generating duplicate id attributes
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Trott authored and targos committed Jan 14, 2022
1 parent 23f97ec commit c12cbf2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions tools/doc/allhtml.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,32 @@ for (const link of toc.match(/<a.*?>/g)) {
.replace(/[\s\S]*?id="toc"[^>]*>\s*<\w+>.*?<\/\w+>\s*(<ul>\s*)?/, '')
// Prefix TOC links with current module name
.replace(/<a href="#(?!DEP[0-9]{4})([^"]+)"/g, (match, anchor) => {
return `<a href="#${moduleName}_${anchor}"`;
return `<a href="#all_${moduleName}_${anchor}"`;
});

apicontent += '<section>' + data.slice(match.index + match[0].length)
.replace(/<!-- API END -->[\s\S]*/, '</section>')
// Prefix all in-page anchor marks with module name
.replace(/<a class="mark" href="#([^"]+)" id="([^"]+)"/g, (match, anchor, id) => {
if (anchor !== id) throw new Error(`Mark does not match: ${anchor} should match ${id}`);
return `<a class="mark" href="#${moduleName}_${anchor}" id="${moduleName}_${anchor}"`;
return `<a class="mark" href="#all_${moduleName}_${anchor}" id="all_${moduleName}_${anchor}"`;
})
// Prefix all in-page links with current module name
.replace(/<a href="#(?!DEP[0-9]{4})([^"]+)"/g, (match, anchor) => {
return `<a href="#${moduleName}_${anchor}"`;
return `<a href="#all_${moduleName}_${anchor}"`;
})
// Update footnote id attributes on anchors
.replace(/<a href="([^"]+)" id="(user-content-fn[^"]+)"/g, (match, href, id) => {
return `<a href="${href}" id="${moduleName}_${id}"`;
return `<a href="${href}" id="all_${moduleName}_${id}"`;
})
// Update footnote id attributes on list items
.replace(/<(\S+) id="(user-content-fn-\d+)"/g, (match, tagName, id) => {
return `<${tagName} id="${moduleName}_${id}"`;
.replace(/<(\S+) id="(user-content-fn[^"]+)"/g, (match, tagName, id) => {
return `<${tagName} id="all_${moduleName}_${id}"`;
})
// Prefix all links to other docs modules with those module names
.replace(/<a href="((\w[^#"]*)\.html)#/g, (match, href, linkModule) => {
if (!htmlFiles.includes(href)) return match;
return `<a href="#${linkModule}_`;
return `<a href="#all_${linkModule}_`;
})
.trim() + '\n';

Expand Down

0 comments on commit c12cbf2

Please sign in to comment.