Skip to content

Commit

Permalink
tools: shorten metadata parsing
Browse files Browse the repository at this point in the history
PR-URL: #19512
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
tniessen committed Mar 25, 2018
1 parent 5b9f8e1 commit 337e040
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions tools/doc/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,28 @@ function arrify(value) {
}

function extractAndParseYAML(text) {
text = text.trim();

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

// js-yaml.safeLoad() throws on error
const meta = yaml.safeLoad(text);

const added = meta.added;
if (added) {
if (meta.added) {
// Since semver-minors can trickle down to previous major versions,
// features may have been added in multiple versions.
meta.added = arrify(added);
meta.added = arrify(meta.added);
}

const deprecated = meta.deprecated;
if (deprecated) {
if (meta.deprecated) {
// Treat deprecated like added for consistency.
meta.deprecated = arrify(deprecated);
meta.deprecated = arrify(meta.deprecated);
}

meta.changes = meta.changes || [];
meta.changes.forEach((entry) => {
for (const entry of meta.changes) {
entry.description = entry.description.replace(/^\^\s*/, '');
});
}

return meta;
}
Expand Down

0 comments on commit 337e040

Please sign in to comment.