Skip to content

Commit

Permalink
tools, doc: fix stability index isssues
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vsemozhetbyt authored and MylesBorins committed May 22, 2018
1 parent b2fb1d7 commit e1ff587
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions tools/doc/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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}" ` +
Expand Down

0 comments on commit e1ff587

Please sign in to comment.