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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
tniessen authored and MylesBorins committed Aug 17, 2018
1 parent aa3be00 commit 11b8d47
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 11b8d47

Please sign in to comment.