Skip to content

Commit ea13763

Browse files
addaleaxMyles Borins
authored and
Myles Borins
committed
tools: allow multiple added: version entries
Allow multiple `added:` version entries, since semver-minors can trickle down to previous major versions, and thus features may have been added in multiple versions. Also include `deprecated:` entries and apply the same logic to them for consistency. Stylize the added HTML as `Added in:` and `Deprecated since:`. PR-URL: #6495 Reviewed-By: Robert Jefe Lindstaedt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 8f76d7d commit ea13763

File tree

5 files changed

+58
-11
lines changed

5 files changed

+58
-11
lines changed

test/doctool/test-doctool-html.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@ const testData = [
3434
' id="foo_sample_markdown_with_yaml_info">#</a></span></h1>' +
3535
'<h2>Foobar<span><a class="mark" href="#foo_foobar" ' +
3636
'id="foo_foobar">#</a></span></h2>' +
37-
'<div class="api_metadata"><span>Added: v1.0.0</span></div> ' +
37+
'<div class="api_metadata"><span>Added in: v1.0.0</span></div> ' +
3838
'<p>Describe <code>Foobar</code> in more detail here.</p>' +
39+
'<h2>Foobar II<span><a class="mark" href="#foo_foobar_ii" ' +
40+
'id="foo_foobar_ii">#</a></span></h2>' +
41+
'<div class="api_metadata"><span>Added in: v5.3.0, v4.2.0</span></div> ' +
42+
'<p>Describe <code>Foobar II</code> in more detail here.</p>' +
3943
'<h2>Deprecated thingy<span><a class="mark" ' +
4044
'href="#foo_deprecated_thingy" id="foo_deprecated_thingy">#</a>' +
4145
'</span></h2>' +
42-
'<div class="api_metadata"><span>Added: v1.0.0</span></div><p>Describe ' +
46+
'<div class="api_metadata"><span>Added in: v1.0.0</span>' +
47+
'<span>Deprecated since: v2.0.0</span></div><p>Describe ' +
4348
'<code>Deprecated thingy</code> in more detail here.</p>' +
4449
'<h2>Something<span><a class="mark" href="#foo_something" ' +
4550
'id="foo_something">#</a></span></h2> ' +

test/doctool/test-doctool-json.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,30 @@ var testData = [
7878
'textRaw': 'Foobar',
7979
'name': 'foobar',
8080
'meta': {
81-
'added': 'v1.0.0'
81+
'added': ['v1.0.0']
8282
},
8383
'desc': '<p>Describe <code>Foobar</code> in more detail ' +
8484
'here.\n\n</p>\n',
8585
'type': 'module',
8686
'displayName': 'Foobar'
8787
},
88+
{
89+
'textRaw': 'Foobar II',
90+
'name': 'foobar_ii',
91+
'meta': {
92+
'added': ['v5.3.0', 'v4.2.0']
93+
},
94+
'desc': '<p>Describe <code>Foobar II</code> in more detail ' +
95+
'here.\n\n</p>\n',
96+
'type': 'module',
97+
'displayName': 'Foobar II'
98+
},
8899
{
89100
'textRaw': 'Deprecated thingy',
90101
'name': 'deprecated_thingy',
91102
'meta': {
92-
'added': 'v1.0.0',
93-
'deprecated': 'v2.0.0'
103+
'added': ['v1.0.0'],
104+
'deprecated': ['v2.0.0']
94105
},
95106
'desc': '<p>Describe <code>Deprecated thingy</code> in more ' +
96107
'detail here.\n\n</p>\n',

test/fixtures/doc_with_yaml.md

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ added: v1.0.0
77

88
Describe `Foobar` in more detail here.
99

10+
## Foobar II
11+
<!-- YAML
12+
added:
13+
- v5.3.0
14+
- v4.2.0
15+
-->
16+
17+
Describe `Foobar II` in more detail here.
18+
1019
## Deprecated thingy
1120
<!-- YAML
1221
added: v1.0.0

tools/doc/common.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,33 @@ function isYAMLBlock(text) {
88

99
exports.isYAMLBlock = isYAMLBlock;
1010

11+
function arrify(value) {
12+
return Array.isArray(value) ? value : [value];
13+
}
14+
1115
function extractAndParseYAML(text) {
1216
text = text.trim();
1317

1418
text = text.replace(/^<!-- YAML/, '')
1519
.replace(/-->$/, '');
1620

1721
// js-yaml.safeLoad() throws on error
18-
return yaml.safeLoad(text);
22+
const meta = yaml.safeLoad(text);
23+
24+
const added = meta.added || meta.Added;
25+
if (added) {
26+
// Since semver-minors can trickle down to previous major versions,
27+
// features may have been added in multiple versions.
28+
meta.added = arrify(added);
29+
}
30+
31+
const deprecated = meta.deprecated || meta.Deprecated;
32+
if (deprecated) {
33+
// Treat deprecated like added for consistency.
34+
meta.deprecated = arrify(deprecated);
35+
}
36+
37+
return meta;
1938
}
2039

2140
exports.extractAndParseYAML = extractAndParseYAML;

tools/doc/html.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,18 @@ function parseLists(input) {
180180

181181
function parseYAML(text) {
182182
const meta = common.extractAndParseYAML(text);
183-
let html = '<div class="api_metadata">';
183+
const html = ['<div class="api_metadata">'];
184184

185-
if (meta.added || meta.Added) {
186-
meta.added = meta.added || meta.Added;
185+
if (meta.added) {
186+
html.push(`<span>Added in: ${meta.added.join(', ')}</span>`);
187+
}
187188

188-
html += '<span>Added: ' + meta.added + '</span>';
189+
if (meta.deprecated) {
190+
html.push(`<span>Deprecated since: ${meta.deprecated.join(', ')} </span>`);
189191
}
190192

191-
return html + '</div>';
193+
html.push('</div>');
194+
return html.join('\n');
192195
}
193196

194197
// Syscalls which appear in the docs, but which only exist in BSD / OSX

0 commit comments

Comments
 (0)