doc: refactor deprecation anchors

PR-URL: https://github.com/nodejs/node/pull/34955
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Antoine du HAMEL authored and Richard Lau committed 2020-09-07 12:29:21 -04:00
1 parent 44d89a9faa
commit 8c207c67d1
2 files changed
+12 -145

No files matched your search

File diff suppressed because it is too large. Load diff
+12 -1
View File
@@ -327,6 +327,7 @@ function versionSort(a, b) {
return +b.match(numberRe)[0] - +a.match(numberRe)[0];
}
const DEPRECATION_HEADING_PATTERN = /^DEP\d+:/;
function buildToc({ filename, apilinks }) {
return (tree, file) => {
const idCounters = Object.create(null);
@@ -349,10 +350,20 @@ function buildToc({ filename, apilinks }) {
node.position.end.offset).trim();
const id = getId(`${realFilename}_${headingText}`, idCounters);
const isDeprecationHeading =
DEPRECATION_HEADING_PATTERN.test(headingText);
if (isDeprecationHeading) {
if (!node.data) node.data = {};
if (!node.data.hProperties) node.data.hProperties = {};
node.data.hProperties.id =
headingText.substring(0, headingText.indexOf(':'));
}
const hasStability = node.stability !== undefined;
toc += ' '.repeat((depth - 1) * 2) +
(hasStability ? `* <span class="stability_${node.stability}">` : '* ') +
`<a href="#${id}">${headingText}</a>${hasStability ? '</span>' : ''}\n`;
`<a href="#${isDeprecationHeading ? node.data.hProperties.id : id}">` +
`${headingText}</a>${hasStability ? '</span>' : ''}\n`;
let anchor =
`<span><a class="mark" href="#${id}" id="${id}">#</a></span>`;