extract_description.js 509 B

123456789101112131415
  1. module.exports = extractDescription
  2. // Extracts description from contents of a readme file in markdown format
  3. function extractDescription (d) {
  4. if (!d) return;
  5. if (d === "ERROR: No README data found!") return;
  6. // the first block of text before the first heading
  7. // that isn't the first line heading
  8. d = d.trim().split('\n')
  9. for (var s = 0; d[s] && d[s].trim().match(/^(#|$)/); s ++);
  10. var l = d.length
  11. for (var e = s + 1; e < l && d[e].trim(); e ++);
  12. return d.slice(s, e).join(' ').trim()
  13. }