Last active
August 5, 2016 12:51
-
-
Save apaleslimghost/e28823b5a785f0491e186533a50e3ebd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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