diff --git a/test/doctool/test-doctool-html.js b/test/doctool/test-doctool-html.js index 7aa8841451..1eb96751cc 100644 --- a/test/doctool/test-doctool-html.js +++ b/test/doctool/test-doctool-html.js @@ -34,12 +34,17 @@ const testData = [ ' id="foo_sample_markdown_with_yaml_info">#' + '

Foobar#

' + - '
Added: v1.0.0
' + + '
Added in: v1.0.0
' + '

Describe Foobar in more detail here.

' + + '

Foobar II#

' + + '
Added in: v5.3.0, v4.2.0
' + + '

Describe Foobar II in more detail here.

' + '

Deprecated thingy#' + '

' + - '
Added: v1.0.0

Describe ' + + '

Added in: v1.0.0' + + 'Deprecated since: v2.0.0

Describe ' + 'Deprecated thingy in more detail here.

' + '

Something#

' + diff --git a/test/doctool/test-doctool-json.js b/test/doctool/test-doctool-json.js index ed7eb64a0e..83563cb2d2 100644 --- a/test/doctool/test-doctool-json.js +++ b/test/doctool/test-doctool-json.js @@ -78,19 +78,30 @@ var testData = [ 'textRaw': 'Foobar', 'name': 'foobar', 'meta': { - 'added': 'v1.0.0' + 'added': ['v1.0.0'] }, 'desc': '

Describe Foobar in more detail ' + 'here.\n\n

\n', 'type': 'module', 'displayName': 'Foobar' }, + { + 'textRaw': 'Foobar II', + 'name': 'foobar_ii', + 'meta': { + 'added': ['v5.3.0', 'v4.2.0'] + }, + 'desc': '

Describe Foobar II in more detail ' + + 'here.\n\n

\n', + 'type': 'module', + 'displayName': 'Foobar II' + }, { 'textRaw': 'Deprecated thingy', 'name': 'deprecated_thingy', 'meta': { - 'added': 'v1.0.0', - 'deprecated': 'v2.0.0' + 'added': ['v1.0.0'], + 'deprecated': ['v2.0.0'] }, 'desc': '

Describe Deprecated thingy in more ' + 'detail here.\n\n

\n', diff --git a/test/fixtures/doc_with_yaml.md b/test/fixtures/doc_with_yaml.md index 03411d5bf7..493c2e7e42 100644 --- a/test/fixtures/doc_with_yaml.md +++ b/test/fixtures/doc_with_yaml.md @@ -7,6 +7,15 @@ added: v1.0.0 Describe `Foobar` in more detail here. +## Foobar II + + +Describe `Foobar II` in more detail here. + ## Deprecated thingy $/, ''); // js-yaml.safeLoad() throws on error - return yaml.safeLoad(text); + const meta = yaml.safeLoad(text); + + const added = meta.added || meta.Added; + if (added) { + // Since semver-minors can trickle down to previous major versions, + // features may have been added in multiple versions. + meta.added = arrify(added); + } + + const deprecated = meta.deprecated || meta.Deprecated; + if (deprecated) { + // Treat deprecated like added for consistency. + meta.deprecated = arrify(deprecated); + } + + return meta; } exports.extractAndParseYAML = extractAndParseYAML; diff --git a/tools/doc/html.js b/tools/doc/html.js index d31125caaa..977e0834d4 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -180,15 +180,18 @@ function parseLists(input) { function parseYAML(text) { const meta = common.extractAndParseYAML(text); - let html = '
'; + const html = ['
']; - if (meta.added || meta.Added) { - meta.added = meta.added || meta.Added; + if (meta.added) { + html.push(`Added in: ${meta.added.join(', ')}`); + } - html += 'Added: ' + meta.added + ''; + if (meta.deprecated) { + html.push(`Deprecated since: ${meta.deprecated.join(', ')} `); } - return html + '
'; + html.push('
'); + return html.join('\n'); } // Syscalls which appear in the docs, but which only exist in BSD / OSX