UNPKG

814 BJavaScriptView 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('{{!(?:--)?' + regex + '(?:--)?}}', 'mig');
9
10 return function parse(contents, file) {
11 var comments = [];
12
13 eol.split(contents).forEach(function (line, index) {
14 var match = commentsRegex.exec(line);
15 while (match) {
16 var comment = commentsUtil.prepareComment(match, index + 1, file);
17 if (!comment) {
18 break;
19 }
20 comments.push(comment);
21 match = commentsRegex.exec(line);
22 }
23 });
24 return comments;
25 };
26};