UNPKG

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