Skip to content

Commit

Permalink
Catch when we're dealing with a comment and just ignore it.
Browse files Browse the repository at this point in the history
  • Loading branch information
rayd committed Jun 27, 2016
1 parent 7caf311 commit 3b4e3c1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ module.exports = function parse(html, options) {
inComponent = false;
}
}
// check if this is a comment tag. if so, just return.
if (tag.indexOf('<!--') === 0) {
return;
}
var isOpen = tag.charAt(1) !== '/';
var start = index + tag.length;
var nextChar = html.charAt(start);
Expand Down
12 changes: 12 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,18 @@ test('parse', function (t) {
{ type: 'text', content: 'There' }
]
}], 'should remove text nodes that are nothing but whitespace');

html = '<!--\n\t<style type="text/css">\n\t\t.header {\n\t\t\tfont-size: 14px;\n\t\t}\n\t</style>\n\n-->\n<div>Hi</div>';
parsed = HTML.parse(html);
t.deepEqual(parsed, [{
type: 'tag',
name: 'div',
attrs: {},
voidElement: false,
children: [
{ type: 'text', content: 'Hi'}
]
}], 'should ignore HTML comments');
t.end();
});

Expand Down

0 comments on commit 3b4e3c1

Please sign in to comment.