Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2021-01-24 05:58:26 +0300
committerMichaƫl Zasso <targos@protonmail.com>2021-02-02 12:50:59 +0300
commit9b9a1801baeb6378e83ca0a9cdf3677f21cebd4d (patch)
tree7b991063cacab85381d0538e18372b062e1609ce /tools
parent181719d4c41861b5b3c3dc99ca6c121a9a776665 (diff)
doc: remove TOC summary for pages with no TOC
Remove the table of contents summary for pages with no table of contents. Currently, this affects at least index.html. PR-URL: https://github.com/nodejs/node/pull/37043 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/doc/allhtml.js4
-rw-r--r--tools/doc/html.js20
2 files changed, 16 insertions, 8 deletions
diff --git a/tools/doc/allhtml.js b/tools/doc/allhtml.js
index 5a24cee4292..93197f812e1 100644
--- a/tools/doc/allhtml.js
+++ b/tools/doc/allhtml.js
@@ -59,9 +59,11 @@ let all = toc.replace(/index\.html/g, 'all.html')
all = all.replace(/<title>.*?\| /, '<title>');
// Insert the combined table of contents.
-const tocStart = /<\w+ id="toc"[^>]*>\s*<\w+>.*?<\/\w+>\s*/.exec(all);
+const tocStart = /<!-- TOC -->/.exec(all);
all = all.slice(0, tocStart.index + tocStart[0].length) +
+ '<details id="toc" open><summary>Table of contents</summary>\n' +
'<ul>\n' + contents + '</ul>\n' +
+ '</details>\n' +
all.slice(tocStart.index + tocStart[0].length);
// Replace apicontent with the concatenated set of apicontents from each source.
diff --git a/tools/doc/html.js b/tools/doc/html.js
index d35fd47b601..6eb3484052b 100644
--- a/tools/doc/html.js
+++ b/tools/doc/html.js
@@ -382,13 +382,19 @@ function buildToc({ filename, apilinks }) {
node.children.push({ type: 'html', value: anchor });
});
- file.toc = unified()
- .use(markdown)
- .use(gfm)
- .use(remark2rehype, { allowDangerousHtml: true })
- .use(raw)
- .use(htmlStringify)
- .processSync(toc).toString();
+ if (toc !== '') {
+ file.toc = '<details id="toc" open><summary>Table of contents</summary>' +
+ unified()
+ .use(markdown)
+ .use(gfm)
+ .use(remark2rehype, { allowDangerousHtml: true })
+ .use(raw)
+ .use(htmlStringify)
+ .processSync(toc).toString() +
+ '</details>';
+ } else {
+ file.toc = '<!-- TOC -->';
+ }
};
}