@@ -56,7 +56,7 @@ function toHTML({ input, filename, nodeVersion, analytics }, cb) {
56
56
const section = firstHeading ? firstHeading . text : 'Index' ;
57
57
58
58
preprocessText ( lexed ) ;
59
- preprocessElements ( lexed ) ;
59
+ preprocessElements ( lexed , filename ) ;
60
60
61
61
// Generate the table of contents. This mutates the lexed contents in-place.
62
62
const toc = buildToc ( lexed , filename ) ;
@@ -171,7 +171,7 @@ function linkJsTypeDocs(text) {
171
171
}
172
172
173
173
// Preprocess stability blockquotes and YAML blocks.
174
- function preprocessElements ( lexed ) {
174
+ function preprocessElements ( lexed , filename ) {
175
175
const STABILITY_RE = / ( .* : ) \s * ( \d ) ( [ \s \S ] * ) / ;
176
176
let state = null ;
177
177
let headingIndex = - 1 ;
@@ -205,10 +205,16 @@ function preprocessElements(lexed) {
205
205
headingIndex = - 1 ;
206
206
heading = null ;
207
207
}
208
+
209
+ // Do not link to the section we are already in.
210
+ const noLinking = filename === 'documentation' &&
211
+ heading !== null && heading . text === 'Stability Index' ;
208
212
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>`
211
216
. replace ( / \n / g, ' ' ) ;
217
+
212
218
lexed [ index ] = { type : 'html' , text : token . text } ;
213
219
} else if ( state === 'MAYBE_STABILITY_BQ' ) {
214
220
state = null ;
@@ -298,9 +304,12 @@ function buildToc(lexed, filename) {
298
304
const realFilename = path . basename ( realFilenames [ 0 ] , '.md' ) ;
299
305
const headingText = token . text . trim ( ) ;
300
306
const id = getId ( `${ realFilename } _${ headingText } ` , idCounters ) ;
307
+
308
+ const hasStability = token . stability !== undefined ;
301
309
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
+
304
313
token . text += `<span><a class="mark" href="#${ id } " id="${ id } ">#</a></span>` ;
305
314
if ( realFilename === 'errors' && headingText . startsWith ( 'ERR_' ) ) {
306
315
token . text += `<span><a class="mark" href="#${ headingText } " ` +
0 commit comments