UNPKG

1.3 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 bangComment = new RegExp('{#' + regex + '#}', 'mig');
9 var htmlComment = new RegExp('<!--' + regex + '-->', 'mig');
10
11 return function parse(contents, file) {
12 var comments = [];
13
14 eol.split(contents).forEach(function (line, index) {
15 var bangCommentMatch = bangComment.exec(line);
16 var comment;
17 while (bangCommentMatch) {
18 comment = commentsUtil.prepareComment(bangCommentMatch, index + 1, file);
19 if (!comment) {
20 break;
21 }
22 comments.push(comment);
23 bangCommentMatch = bangComment.exec(line);
24 }
25
26 var htmlCommentMatch = htmlComment.exec(line);
27 while (htmlCommentMatch) {
28 comment = commentsUtil.prepareComment(htmlCommentMatch, index + 1, file);
29 if (!comment) {
30 break;
31 }
32 comments.push(comment);
33 htmlCommentMatch = htmlComment.exec(line);
34 }
35 });
36 return comments;
37 };
38};