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';
|
||||
|
||||
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 = `<div class="api_stability api_stability_${number}">` +
|
||||
'<a href="documentation.html#documentation_stability_index">' +
|
||||
`${prefix} ${number}</a>${explication}</div>`
|
||||
(noLinking ? '' :
|
||||
'<a href="documentation.html#documentation_stability_index">') +
|
||||
`${prefix} ${number}${noLinking ? '' : '</a>'}${explication}</div>`
|
||||
.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) +
|
||||
`* <span class="stability_${token.stability}">` +
|
||||
`<a href="#${id}">${token.text}</a></span>\n`;
|
||||
(hasStability ? `* <span class="stability_${token.stability}">` : '* ') +
|
||||
`<a href="#${id}">${token.text}</a>${hasStability ? '</span>' : ''}\n`;
|
||||
|
||||
token.text += `<span><a class="mark" href="#${id}" id="${id}">#</a></span>`;
|
||||
if (realFilename === 'errors' && headingText.startsWith('ERR_')) {
|
||||
token.text += `<span><a class="mark" href="#${headingText}" ` +
|
||||
|
Loading…
x
Reference in New Issue
Block a user