From 94f82553aaa66e4e2d6c356ffe57709a0ebe95cd Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 1 May 2016 01:51:38 +0200 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/6495 Reviewed-By: Robert Jefe Lindstaedt Reviewed-By: James M Snell Reviewed-By: Jeremiah Senkpiel --- test/doctool/test-doctool-html.js | 9 +++++++-- test/doctool/test-doctool-json.js | 17 ++++++++++++++--- test/fixtures/doc_with_yaml.md | 9 +++++++++ tools/doc/common.js | 21 ++++++++++++++++++++- tools/doc/html.js | 13 ++++++++----- 5 files changed, 58 insertions(+), 11 deletions(-) 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#

' + - ' ' + + ' ' + '

Describe Foobar in more detail here.

' + + '

Foobar II#

' + + ' ' + + '

Describe Foobar II in more detail here.

' + '

Deprecated thingy#' + '

' + - '

Describe ' + + '

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 = ''); + return html.join('\n'); } // Syscalls which appear in the docs, but which only exist in BSD / OSX