Skip to content

Commit bfb8f68

Browse files
committed
Add support for parsing comments
1 parent 8c227b9 commit bfb8f68

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ module.exports = function() {
1414
ontext: function(text) {
1515
parent.push(['#text', text]);
1616
},
17+
oncomment: function(text) {
18+
parent.push(['#comment', text]);
19+
},
1720
onclosetag: function() {
1821
var p = parent.parent;
1922
// Delete elementList and/or attributes if empty

test/05-comments/expected.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
["#comment", " this is a comment "],
3+
["#text", "\nNot a comment\n"],
4+
["#comment", " another comment "]
5+
]

test/05-comments/markup.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- this is a comment -->
2+
Not a comment
3+
<!-- another comment -->

test/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ test('should not set a attribute hash on the node if it has none', function(t) {
2828

2929
test('should parse nested tags and text nodes', function(t) {
3030
verify('04-nested-tags', t);
31+
});
32+
33+
test('should parse comments', function(t) {
34+
verify('05-comments', t);
3135
});

0 commit comments

Comments
 (0)