From 6bc5528bcd28f536d99af6ba2faf39ba29899f87 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 7aa88414515681..1eb96751cc0adb 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 ed7eb64a0e961d..83563cb2d2cdac 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 03411d5bf7b295..493c2e7e4268b2 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 d31125caaa05e0..977e0834d48304 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