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: https://github.com/nodejs/node/pull/20731 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
parent
7bd48896e9
commit
2773de52fd
@ -56,7 +56,7 @@ function toHTML({ input, filename, nodeVersion, analytics }, cb) {
|
|||||||
const section = firstHeading ? firstHeading.text : 'Index';
|
const section = firstHeading ? firstHeading.text : 'Index';
|
||||||
|
|
||||||
preprocessText(lexed);
|
preprocessText(lexed);
|
||||||
preprocessElements(lexed);
|
preprocessElements(lexed, filename);
|
||||||
|
|
||||||
// Generate the table of contents. This mutates the lexed contents in-place.
|
// Generate the table of contents. This mutates the lexed contents in-place.
|
||||||
const toc = buildToc(lexed, filename);
|
const toc = buildToc(lexed, filename);
|
||||||
@ -171,7 +171,7 @@ function linkJsTypeDocs(text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Preprocess stability blockquotes and YAML blocks.
|
// Preprocess stability blockquotes and YAML blocks.
|
||||||
function preprocessElements(lexed) {
|
function preprocessElements(lexed, filename) {
|
||||||
const STABILITY_RE = /(.*:)\s*(\d)([\s\S]*)/;
|
const STABILITY_RE = /(.*:)\s*(\d)([\s\S]*)/;
|
||||||
let state = null;
|
let state = null;
|
||||||
let headingIndex = -1;
|
let headingIndex = -1;
|
||||||
@ -205,10 +205,16 @@ function preprocessElements(lexed) {
|
|||||||
headingIndex = -1;
|
headingIndex = -1;
|
||||||
heading = null;
|
heading = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do not link to the section we are already in.
|
||||||
|
const noLinking = filename === 'documentation' &&
|
||||||
|
heading !== null && heading.text === 'Stability Index';
|
||||||
token.text = `<div class="api_stability api_stability_${number}">` +
|
token.text = `<div class="api_stability api_stability_${number}">` +
|
||||||
'<a href="documentation.html#documentation_stability_index">' +
|
(noLinking ? '' :
|
||||||
`${prefix} ${number}</a>${explication}</div>`
|
'<a href="documentation.html#documentation_stability_index">') +
|
||||||
|
`${prefix} ${number}${noLinking ? '' : '</a>'}${explication}</div>`
|
||||||
.replace(/\n/g, ' ');
|
.replace(/\n/g, ' ');
|
||||||
|
|
||||||
lexed[index] = { type: 'html', text: token.text };
|
lexed[index] = { type: 'html', text: token.text };
|
||||||
} else if (state === 'MAYBE_STABILITY_BQ') {
|
} else if (state === 'MAYBE_STABILITY_BQ') {
|
||||||
state = null;
|
state = null;
|
||||||
@ -298,9 +304,12 @@ function buildToc(lexed, filename) {
|
|||||||
const realFilename = path.basename(realFilenames[0], '.md');
|
const realFilename = path.basename(realFilenames[0], '.md');
|
||||||
const headingText = token.text.trim();
|
const headingText = token.text.trim();
|
||||||
const id = getId(`${realFilename}_${headingText}`, idCounters);
|
const id = getId(`${realFilename}_${headingText}`, idCounters);
|
||||||
|
|
||||||
|
const hasStability = token.stability !== undefined;
|
||||||
toc += ' '.repeat((depth - 1) * 2) +
|
toc += ' '.repeat((depth - 1) * 2) +
|
||||||
`* <span class="stability_${token.stability}">` +
|
(hasStability ? `* <span class="stability_${token.stability}">` : '* ') +
|
||||||
`<a href="#${id}">${token.text}</a></span>\n`;
|
`<a href="#${id}">${token.text}</a>${hasStability ? '</span>' : ''}\n`;
|
||||||
|
|
||||||
token.text += `<span><a class="mark" href="#${id}" id="${id}">#</a></span>`;
|
token.text += `<span><a class="mark" href="#${id}" id="${id}">#</a></span>`;
|
||||||
if (realFilename === 'errors' && headingText.startsWith('ERR_')) {
|
if (realFilename === 'errors' && headingText.startsWith('ERR_')) {
|
||||||
token.text += `<span><a class="mark" href="#${headingText}" ` +
|
token.text += `<span><a class="mark" href="#${headingText}" ` +
|
||||||
|
Loading…
x
Reference in New Issue
Block a user