Skip to content

Instantly share code, notes, and snippets.

@apaleslimghost
Last active August 5, 2016 12:51
Show Gist options
  • Save apaleslimghost/e28823b5a785f0491e186533a50e3ebd to your computer and use it in GitHub Desktop.
Save apaleslimghost/e28823b5a785f0491e186533a50e3ebd to your computer and use it in GitHub Desktop.
module.exports = function parseMakeCommentBlocks(text) {
const lines = text.split('\n');
return lines.reduce((blocks, line, i) => {
const lastBlock = blocks[blocks.length - 1];
if(line[0] === '#') {
const trimmedLine = line.slice(1).trim();
if(!lastBlock || lastBlock.nextLine) {
return blocks.concat({
comment: trimmedLine,
});
}
lastBlock.comment += '\n' + trimmedLine;
return blocks;
}
if(lastBlock && !lastBlock.nextLine) {
lastBlock.nextLine = line;
lastBlock.lineNumber = i + 1;
}
return blocks;
}, []);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment