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 <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent b2fb1d7 commit e1ff587

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

‎tools/doc/html.js‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function toHTML({ input, filename, nodeVersion, analytics }, cb) {
5656
constsection=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
consttoc=buildToc(lexed,filename);
@@ -171,7 +171,7 @@ function linkJsTypeDocs(text) {
171171
}
172172

173173
// Preprocess stability blockquotes and YAML blocks.
174-
functionpreprocessElements(lexed){
174+
functionpreprocessElements(lexed,filename){
175175
constSTABILITY_RE=/(.*:)\s*(\d)([\s\S]*)/;
176176
letstate=null;
177177
letheadingIndex=-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+
constnoLinking=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
}elseif(state==='MAYBE_STABILITY_BQ'){
214220
state=null;
@@ -298,9 +304,12 @@ function buildToc(lexed, filename) {
298304
constrealFilename=path.basename(realFilenames[0],'.md');
299305
constheadingText=token.text.trim();
300306
constid=getId(`${realFilename}_${headingText}`,idCounters);
307+
308+
consthasStability=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)