Skip to content

Commit e1ff587

Browse files
vsemozhetbytMylesBorins
authored andcommitted
tools, doc: fix stability index isssues
1. Do not autolink in doc stability section. 2. Do not add void wrapping elements to docs. PR-URL: #20731 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent b2fb1d7 commit e1ff587

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

tools/doc/html.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function toHTML({ input, filename, nodeVersion, analytics }, cb) {
5656
const section = firstHeading ? firstHeading.text : 'Index';
5757

5858
preprocessText(lexed);
59-
preprocessElements(lexed);
59+
preprocessElements(lexed, filename);
6060

6161
// Generate the table of contents. This mutates the lexed contents in-place.
6262
const toc = buildToc(lexed, filename);
@@ -171,7 +171,7 @@ function linkJsTypeDocs(text) {
171171
}
172172

173173
// Preprocess stability blockquotes and YAML blocks.
174-
function preprocessElements(lexed) {
174+
function preprocessElements(lexed, filename) {
175175
const STABILITY_RE = /(.*:)\s*(\d)([\s\S]*)/;
176176
let state = null;
177177
let headingIndex = -1;
@@ -205,10 +205,16 @@ function preprocessElements(lexed) {
205205
headingIndex = -1;
206206
heading = null;
207207
}
208+
209+
// Do not link to the section we are already in.
210+
const noLinking = filename === 'documentation' &&
211+
heading !== null && heading.text === 'Stability Index';
208212
token.text = `<div class="api_stability api_stability_${number}">` +
209-
'<a href="documentation.html#documentation_stability_index">' +
210-
`${prefix} ${number}</a>${explication}</div>`
213+
(noLinking ? '' :
214+
'<a href="documentation.html#documentation_stability_index">') +
215+
`${prefix} ${number}${noLinking ? '' : '</a>'}${explication}</div>`
211216
.replace(/\n/g, ' ');
217+
212218
lexed[index] = { type: 'html', text: token.text };
213219
} else if (state === 'MAYBE_STABILITY_BQ') {
214220
state = null;
@@ -298,9 +304,12 @@ function buildToc(lexed, filename) {
298304
const realFilename = path.basename(realFilenames[0], '.md');
299305
const headingText = token.text.trim();
300306
const id = getId(`${realFilename}_${headingText}`, idCounters);
307+
308+
const hasStability = token.stability !== undefined;
301309
toc += ' '.repeat((depth - 1) * 2) +
302-
`* <span class="stability_${token.stability}">` +
303-
`<a href="#${id}">${token.text}</a></span>\n`;
310+
(hasStability ? `* <span class="stability_${token.stability}">` : '* ') +
311+
`<a href="#${id}">${token.text}</a>${hasStability ? '</span>' : ''}\n`;
312+
304313
token.text += `<span><a class="mark" href="#${id}" id="${id}">#</a></span>`;
305314
if (realFilename === 'errors' && headingText.startsWith('ERR_')) {
306315
token.text += `<span><a class="mark" href="#${headingText}" ` +

0 commit comments

Comments
 (0)