');
// Insert the combined table of contents.
const tocStart = //.exec(all);
all = all.slice(0, tocStart.index + tocStart[0].length) +
'Table of contents
\n' +
'\n' +
' \n' +
all.slice(tocStart.index + tocStart[0].length);
// Replace apicontent with the concatenated set of apicontents from each source.
const apiStart = /<\w+ id="apicontent">\s*/.exec(all);
const apiEnd = all.lastIndexOf('');
all = all.slice(0, apiStart.index + apiStart[0].length)
.replace(
'\n',
buildCSSForFlavoredJS(new Set(Array.from(
apicontent.matchAll(/(?<=)/g),
(x) => Number(x[0]),
))) + '\n',
) +
apicontent +
all.slice(apiEnd);
// Write results.
fs.writeFileSync(new URL('./all.html', source), all, 'utf8');
// Validate all hrefs have a target.
const idRe = / id="([^"]+)"/g;
const ids = new Set([...all.matchAll(idRe)].map((match) => match[1]));
const hrefRe = / href="#([^"]+)"/g;
const hrefMatches = all.matchAll(hrefRe);
for (const match of hrefMatches) {
if (!ids.has(match[1])) throw new Error(`link not found: ${match[1]}`);
}