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 ssCommentRegex = new RegExp('<%--' + regex + '--%>', 'mig');
|
9 | var htmlCommentRegex = 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 ssCommentsMatch = ssCommentRegex.exec(line);
|
16 | var comment;
|
17 | while (ssCommentsMatch) {
|
18 | comment = commentsUtil.prepareComment(ssCommentsMatch, index + 1, file);
|
19 | if (!comment) {
|
20 | return;
|
21 | }
|
22 | comments.push(comment);
|
23 | ssCommentsMatch = ssCommentRegex.exec(line);
|
24 | }
|
25 |
|
26 | var htmlCommentMatch = htmlCommentRegex.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 = htmlCommentRegex.exec(line);
|
34 | }
|
35 | });
|
36 | return comments;
|
37 | };
|
38 | };
|