diff --git a/tools/doc/html.js b/tools/doc/html.js index 60cacd5b791bcb..dfd0f22c7c8330 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -56,7 +56,7 @@ function toHTML({ input, filename, nodeVersion, analytics }, cb) { const section = firstHeading ? firstHeading.text : 'Index'; preprocessText(lexed); - preprocessElements(lexed); + preprocessElements(lexed, filename); // Generate the table of contents. This mutates the lexed contents in-place. const toc = buildToc(lexed, filename); @@ -171,7 +171,7 @@ function linkJsTypeDocs(text) { } // Preprocess stability blockquotes and YAML blocks. -function preprocessElements(lexed) { +function preprocessElements(lexed, filename) { const STABILITY_RE = /(.*:)\s*(\d)([\s\S]*)/; let state = null; let headingIndex = -1; @@ -205,10 +205,16 @@ function preprocessElements(lexed) { headingIndex = -1; heading = null; } + + // Do not link to the section we are already in. + const noLinking = filename === 'documentation' && + heading !== null && heading.text === 'Stability Index'; token.text = `
` + - '' + - `${prefix} ${number}${explication}
` + (noLinking ? '' : + '') + + `${prefix} ${number}${noLinking ? '' : ''}${explication}` .replace(/\n/g, ' '); + lexed[index] = { type: 'html', text: token.text }; } else if (state === 'MAYBE_STABILITY_BQ') { state = null; @@ -298,9 +304,12 @@ function buildToc(lexed, filename) { const realFilename = path.basename(realFilenames[0], '.md'); const headingText = token.text.trim(); const id = getId(`${realFilename}_${headingText}`, idCounters); + + const hasStability = token.stability !== undefined; toc += ' '.repeat((depth - 1) * 2) + - `* ` + - `${token.text}\n`; + (hasStability ? `* ` : '* ') + + `${token.text}${hasStability ? '' : ''}\n`; + token.text += `#`; if (realFilename === 'errors' && headingText.startsWith('ERR_')) { token.text += `