Skip to content

Commit 192192a

Browse files
luk-isaacs
authored andcommitted
Colorize API stabilitity index headers in docs
Noted in @shtylman's nodejs#3898, API stability notes are easy to overlook in the html documentation. This can be especially troublesome if the API is deprecated. This commit gives visual feedback by adding in a class to the html docs when they're generated. The API headers with corresponding colors are also listed in the 'About this Documentation' page for easy reference.
1 parent e576208 commit 192192a

3 files changed

Lines changed: 58 additions & 10 deletions

File tree

doc/api/documentation.markdown

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,46 @@ proven, and so relied upon, that they are unlikely to ever change at
3131
all. Others are brand new and experimental, or known to be hazardous
3232
and in the process of being redesigned.
3333

34-
The notices look like this:
35-
36-
Stability: 1 Experimental
37-
3834
The stability indices are as follows:
3935

40-
* **0 - Deprecated** This feature is known to be problematic, and changes are
36+
```
37+
Stability: 0 - Deprecated
38+
This feature is known to be problematic, and changes are
4139
planned. Do not rely on it. Use of the feature may cause warnings. Backwards
4240
compatibility should not be expected.
41+
```
4342

44-
* **1 - Experimental** This feature was introduced recently, and may change
43+
```
44+
Stability: 1 - Experimental
45+
This feature was introduced recently, and may change
4546
or be removed in future versions. Please try it out and provide feedback.
4647
If it addresses a use-case that is important to you, tell the node core team.
48+
```
4749

48-
* **2 - Unstable** The API is in the process of settling, but has not yet had
50+
```
51+
Stability: 2 - Unstable
52+
The API is in the process of settling, but has not yet had
4953
sufficient real-world testing to be considered stable. Backwards-compatibility
5054
will be maintained if reasonable.
55+
```
5156

52-
* **3 - Stable** The API has proven satisfactory, but cleanup in the underlying
57+
```
58+
Stability: 3 - Stable
59+
The API has proven satisfactory, but cleanup in the underlying
5360
code may cause minor changes. Backwards-compatibility is guaranteed.
61+
```
5462

55-
* **4 - API Frozen** This API has been tested extensively in production and is
63+
```
64+
Stability: 4 - API Frozen
65+
This API has been tested extensively in production and is
5666
unlikely to ever have to change.
67+
```
5768

58-
* **5 - Locked** Unless serious bugs are found, this code will not ever
69+
```
70+
Stability: 5 - API Locked
71+
Unless serious bugs are found, this code will not ever
5972
change. Please do not suggest changes in this area; they will be refused.
73+
```
6074

6175
## JSON Output
6276

doc/api_assets/style.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,30 @@ code a:hover {
6767
margin: 0;
6868
}
6969

70+
.api_stability_0 {
71+
border-color: #D60027;
72+
}
73+
74+
.api_stability_1 {
75+
border-color: #EC5315;
76+
}
77+
78+
.api_stability_2 {
79+
border-color: #FFD700;
80+
}
81+
82+
.api_stability_3 {
83+
border-color: #AEC516;
84+
}
85+
86+
.api_stability_4 {
87+
border-color: #009431;
88+
}
89+
90+
.api_stability_5 {
91+
border-color: #0084B6;
92+
}
93+
7094
ul.plain {
7195
list-style: none;
7296
}

tools/doc/html.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ function parseLists(input) {
6969
var output = [];
7070
output.links = input.links;
7171
input.forEach(function(tok) {
72+
if (tok.type === 'code' && tok.text.match(/Stability:.*/g)) {
73+
tok.text = parseAPIHeader(tok.text);
74+
output.push({ type: 'html', text: tok.text });
75+
return;
76+
}
7277
if (state === null) {
7378
if (tok.type === 'heading') {
7479
state = 'AFTERHEADING';
@@ -122,6 +127,11 @@ function parseListItem(text) {
122127
return text;
123128
}
124129

130+
function parseAPIHeader(text) {
131+
text = text.replace(/(.*:)\s(\d)([\s\S]*)/,
132+
'<pre class="api_stability_$2">$1 $2$3</pre>');
133+
return text;
134+
}
125135

126136
// section is just the first heading
127137
function getSection(lexed) {

0 commit comments

Comments
 (0)