1 | 'use strict';
|
2 | var eol = require('eol');
|
3 | var commentsUtil = require('../utils/comments');
|
4 |
|
5 | module.exports = function (params) {
|
6 | params = params || {};
|
7 | var regex = commentsUtil.getRegex(params.customTags);
|
8 | var commentsRegex = new RegExp('^\\s*%' + regex + '$', 'mig');
|
9 |
|
10 | return function parse(contents, file) {
|
11 | var comments = [];
|
12 |
|
13 | eol.split(contents).forEach(function (line, index) {
|
14 | var hashMatch = commentsRegex.exec(line);
|
15 | var comment;
|
16 | while (hashMatch) {
|
17 | comment = commentsUtil.prepareComment(hashMatch, index + 1, file);
|
18 | if (!comment) {
|
19 | break;
|
20 | }
|
21 | comments.push(comment);
|
22 | hashMatch = commentsRegex.exec(line);
|
23 | }
|
24 | });
|
25 | return comments;
|
26 | };
|
27 | };
|