Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
doc: wrap TOC in a <details> tag
PR-URL: #36896
Fixes: #36885
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
Mattia Pontonio authored and aduh95 committed Jan 14, 2021
commit 2ba8728b9f3c80a8625ec72fb7f2ccb9179d940a
4 changes: 2 additions & 2 deletions doc/api_assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ hr {
margin: 0 0 1rem;
}

#toc h2 {
margin: 1.5rem 0;
#toc > ul {
margin-top: 1.5rem;
}

#toc p {
Expand Down
6 changes: 3 additions & 3 deletions doc/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ <h1>Node.js __VERSION__ Documentation</h1>
<hr>
</header>

<div id="toc">
<h2>Table of Contents</h2>
<details id="toc" open>
<summary>Table of Contents</summary>
__TOC__
</div>
</details>

<div id="apicontent">
__CONTENT__
Expand Down
8 changes: 4 additions & 4 deletions tools/doc/allhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ for (const link of toc.match(/<a.*?>/g)) {
const data = fs.readFileSync(source + '/' + href, 'utf8');

// Split the doc.
const match = /(<\/ul>\s*)?<\/div>\s*<div id="apicontent">/.exec(data);
const match = /(<\/ul>\s*)?<\/\w+>\s*<\w+ id="apicontent">/.exec(data);

contents += data.slice(0, match.index)
.replace(/[\s\S]*?<div id="toc">\s*<h2>.*?<\/h2>\s*(<ul>\s*)?/, '');
.replace(/[\s\S]*?id="toc"[^>]*>\s*<\w+>.*?<\/\w+>\s*(<ul>\s*)?/, '');

apicontent += data.slice(match.index + match[0].length)
.replace(/<!-- API END -->[\s\S]*/, '')
Expand All @@ -59,13 +59,13 @@ let all = toc.replace(/index\.html/g, 'all.html')
all = all.replace(/<title>.*?\| /, '<title>');

// Insert the combined table of contents.
const tocStart = /<div id="toc">\s*<h2>.*?<\/h2>\s*/.exec(all);
const tocStart = /<\w+ id="toc"[^>]*>\s*<\w+>.*?<\/\w+>\s*/.exec(all);
all = all.slice(0, tocStart.index + tocStart[0].length) +
'<ul>\n' + contents + '</ul>\n' +
all.slice(tocStart.index + tocStart[0].length);

// Replace apicontent with the concatenated set of apicontents from each source.
const apiStart = /<div id="apicontent">\s*/.exec(all);
const apiStart = /<\w+ id="apicontent">\s*/.exec(all);
const apiEnd = all.lastIndexOf('<!-- API END -->');
all = all.slice(0, apiStart.index + apiStart[0].length) +
apicontent +
Expand Down