Skip to content

Commit 489d7c2

Browse files
committed
Add option 'ignoreHtmlComments'
1 parent 0896397 commit 489d7c2

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

lib/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ function htmlToAST(HTMLDoc) {
3232
* @returns {AST}
3333
*/
3434
function modifyASTTree(tree, options) {
35+
var delComments = [];
36+
3537
_.forEach(tree, function(node) {
3638
if (options.ignoreWhitespace && node.type === 'text') {
3739

@@ -43,6 +45,12 @@ function modifyASTTree(tree, options) {
4345
return;
4446
}
4547

48+
if (options.ignoreHtmlComments && node.type === 'comment') {
49+
delComments.push(tree.indexOf(node));
50+
51+
return;
52+
}
53+
4654
if (node.hasOwnProperty('attribs')) {
4755
var attrs = utils.sortObj(node['attribs']);
4856

@@ -76,6 +84,10 @@ function modifyASTTree(tree, options) {
7684
}
7785
});
7886

87+
for (var i = 0; i < delComments.length; i++) {
88+
tree.splice(delComments[i] - i, 1);
89+
}
90+
7991
return tree;
8092
}
8193

lib/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ exports.defaults = function(options) {
5959
compareHtmlAttrsAsJSON: [],
6060

6161
ignoreWhitespace: true,
62+
ignoreHtmlComments: true,
6263

6364
bem: false
6465
});

0 commit comments

Comments
 (0)