Skip to content

Commit f99b38f

Browse files
Mattia Pontonioruyadorno
Mattia Pontonio
authored andcommitted
doc: wrap TOC in a <details> tag
PR-URL: #36896 Fixes: #36885 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 1149af6 commit f99b38f

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

doc/api_assets/style.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,8 @@ hr {
472472
margin: 0 0 1rem;
473473
}
474474

475-
#toc h2 {
476-
margin: 1.5rem 0;
475+
#toc > ul {
476+
margin-top: 1.5rem;
477477
}
478478

479479
#toc p {

doc/template.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ <h1>Node.js __VERSION__ Documentation</h1>
5555
<hr>
5656
</header>
5757

58-
<div id="toc">
59-
<h2>Table of Contents</h2>
58+
<details id="toc" open>
59+
<summary>Table of Contents</summary>
6060
__TOC__
61-
</div>
61+
</details>
6262

6363
<div id="apicontent">
6464
__CONTENT__

tools/doc/allhtml.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ for (const link of toc.match(/<a.*?>/g)) {
3131
const data = fs.readFileSync(source + '/' + href, 'utf8');
3232

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

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

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

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

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

0 commit comments

Comments
 (0)