Parser.prototype.parse = function()

in app/regenerate-homepage/lib/parser.js [239:314]


Parser.prototype.parse = function(lines) {
  // Preprocess the document to remove top level HTML comments and their content
  lines = this.removeHTMLComments(lines.toString());

  // Split the markdown into lines
  lines = lines.split('\n');

  // Feed blocks of string lines into the header finder.
  // If a header is found in a sample then break the lines to extract
  // the body, and tag it with the header info.
  let numberOfLines = lines.length;
  let block = [];
  let items = [];
  let currentItem;

  for (var i = 0; i < numberOfLines + 1; i++) {
    block.push(lines[i]);

    if (i > 1) {
      block.shift();
    } else if (i === 0) {
      continue;
    } else if (i === numberOfLines) {
      block.push('');
    }

    var header = this.extractHeaderInfo(block);

    // Filter out lines that are just markdown underlines
    var count = (block[0].match(/=/g) || []).length;
    if (count > block[0].length * 0.8) {
      continue;
    }

    if (header) {
      if (currentItem) {
        currentItem.body = currentItem.body.trim();
        items.push(currentItem);
      }

      currentItem = header;
      currentItem.body = '';
    } else {
      if (currentItem) {
        currentItem.body += block[0] + '\n';
      }
    }
  }

  if (currentItem) {
    currentItem.body = currentItem.body.trim();
    items.push(currentItem);
  }

  // Post process to remove some junk items.
  var cleanedItems = [];
  for (var v of items) {

    // Some people are using "semantic-release" package which auto inserts
    // a junk version at the top saying that the changelog was generated using
    // that package. Filter this out
    if (v.version === '0.0.0-semantically-released') {
      continue;
    }

    cleanedItems.push(v);
  }

  // Finally sort the releases in descending order. Some changelogs
  // are in ascending order, and that is kind of annoying, prefer consistency.
  cleanedItems.sort(function(a, b) {
    return compareSemVer(b.version, a.version);
  });

  return cleanedItems;
};