Skip to content

Commit 0d21f95

Browse files
ilfroloffMyles Borins
authored and
Myles Borins
committed
doc: highlight deprecated API in ToC
Highlight deprecated API methods/properties in "Table of Contents" for increasing understandability. Adapted code to eslint standards. PR-URL: #7189 Fixes: nodejs/nodejs.org#772 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent 97748c6 commit 0d21f95

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

doc/api_assets/style.css

+15
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,21 @@ hr {
330330
margin-top: .666em;
331331
}
332332

333+
#toc .stability_0::after {
334+
background-color: #d50027;
335+
color: #fff;
336+
}
337+
338+
#toc .stability_0::after {
339+
content: "deprecated";
340+
font-size: .8em;
341+
position: relative;
342+
top: -.18em;
343+
left: .5em;
344+
padding: 0 .3em .2em;
345+
border-radius: 3px;
346+
}
347+
333348
#apicontent li {
334349
margin-bottom: .5em;
335350
}

tools/doc/html.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const typeParser = require('./type-parser.js');
99

1010
module.exports = toHTML;
1111

12+
const STABILITY_TEXT_REG_EXP = /(.*:)\s*(\d)([\s\S]*)/;
13+
1214
// customized heading without id attribute
1315
var renderer = new marked.Renderer();
1416
renderer.heading = function(text, level) {
@@ -153,8 +155,11 @@ function parseLists(input) {
153155
var savedState = [];
154156
var depth = 0;
155157
var output = [];
158+
let headingIndex = -1;
159+
let heading = null;
160+
156161
output.links = input.links;
157-
input.forEach(function(tok) {
162+
input.forEach(function(tok, index) {
158163
if (tok.type === 'blockquote_start') {
159164
savedState.push(state);
160165
state = 'MAYBE_STABILITY_BQ';
@@ -167,6 +172,17 @@ function parseLists(input) {
167172
if ((tok.type === 'paragraph' && state === 'MAYBE_STABILITY_BQ') ||
168173
tok.type === 'code') {
169174
if (tok.text.match(/Stability:.*/g)) {
175+
const stabilityMatch = tok.text.match(STABILITY_TEXT_REG_EXP);
176+
const stability = Number(stabilityMatch[2]);
177+
const isStabilityIndex =
178+
index - 2 === headingIndex || // general
179+
index - 3 === headingIndex; // with api_metadata block
180+
181+
if (heading && isStabilityIndex) {
182+
heading.stability = stability;
183+
headingIndex = -1;
184+
heading = null;
185+
}
170186
tok.text = parseAPIHeader(tok.text);
171187
output.push({ type: 'html', text: tok.text });
172188
return;
@@ -178,6 +194,8 @@ function parseLists(input) {
178194
if (state === null ||
179195
(state === 'AFTERHEADING' && tok.type === 'heading')) {
180196
if (tok.type === 'heading') {
197+
headingIndex = index;
198+
heading = tok;
181199
state = 'AFTERHEADING';
182200
}
183201
output.push(tok);
@@ -280,7 +298,7 @@ function linkJsTypeDocs(text) {
280298

281299
function parseAPIHeader(text) {
282300
text = text.replace(
283-
/(.*:)\s(\d)([\s\S]*)/,
301+
STABILITY_TEXT_REG_EXP,
284302
'<pre class="api_stability api_stability_$2">$1 $2$3</pre>'
285303
);
286304
return text;
@@ -324,8 +342,8 @@ function buildToc(lexed, filename, cb) {
324342
const realFilename = path.basename(realFilenames[0], '.md');
325343
const id = getId(realFilename + '_' + tok.text.trim());
326344
toc.push(new Array((depth - 1) * 2 + 1).join(' ') +
327-
'* <a href="#' + id + '">' +
328-
tok.text + '</a>');
345+
'* <span class="stability_' + tok.stability + '">' +
346+
'<a href="#' + id + '">' + tok.text + '</a></span>');
329347
tok.text += '<span><a class="mark" href="#' + id + '" ' +
330348
'id="' + id + '">#</a></span>';
331349
});

0 commit comments

Comments
 (0)