@@ -55,6 +55,130 @@ test('parse', function (t) {
5555 ] )
5656 t . equal ( html , HTML . stringify ( parsed ) )
5757
58+ html = '<!-- just a comment node -->'
59+ parsed = HTML . parse ( html )
60+ t . deepEqual ( parsed , [
61+ {
62+ type : 'comment' ,
63+ comment : ' just a comment node ' ,
64+ } ,
65+ ] )
66+ t . equal ( html , HTML . stringify ( parsed ) )
67+
68+ html =
69+ '<div><h2>Comment below this header</h2><!-- just a comment node --></div>'
70+ parsed = HTML . parse ( html )
71+ t . deepEqual ( parsed , [
72+ {
73+ name : 'div' ,
74+ type : 'tag' ,
75+ attrs : { } ,
76+ voidElement : false ,
77+ children : [
78+ {
79+ attrs : { } ,
80+ name : 'h2' ,
81+ type : 'tag' ,
82+ voidElement : false ,
83+ children : [
84+ {
85+ content : 'Comment below this header' ,
86+ type : 'text' ,
87+ } ,
88+ ] ,
89+ } ,
90+ {
91+ type : 'comment' ,
92+ comment : ' just a comment node ' ,
93+ } ,
94+ ] ,
95+ } ,
96+ ] )
97+ t . equal ( html , HTML . stringify ( parsed ) )
98+
99+ html =
100+ '<div><h2>Comment below this header</h2><!-- just a comment node --><!-- subsequent comment node --></div>'
101+ parsed = HTML . parse ( html )
102+ t . deepEqual ( parsed , [
103+ {
104+ name : 'div' ,
105+ type : 'tag' ,
106+ attrs : { } ,
107+ voidElement : false ,
108+ children : [
109+ {
110+ attrs : { } ,
111+ name : 'h2' ,
112+ type : 'tag' ,
113+ voidElement : false ,
114+ children : [
115+ {
116+ content : 'Comment below this header' ,
117+ type : 'text' ,
118+ } ,
119+ ] ,
120+ } ,
121+ {
122+ type : 'comment' ,
123+ comment : ' just a comment node ' ,
124+ } ,
125+ {
126+ type : 'comment' ,
127+ comment : ' subsequent comment node ' ,
128+ } ,
129+ ] ,
130+ } ,
131+ ] )
132+ t . equal ( html , HTML . stringify ( parsed ) )
133+
134+ html = '<div><h2><!-- comment inside h2 tag --></h2></div>'
135+ parsed = HTML . parse ( html )
136+ t . deepEqual ( parsed , [
137+ {
138+ name : 'div' ,
139+ type : 'tag' ,
140+ attrs : { } ,
141+ voidElement : false ,
142+ children : [
143+ {
144+ attrs : { } ,
145+ name : 'h2' ,
146+ type : 'tag' ,
147+ voidElement : false ,
148+ children : [
149+ {
150+ type : 'comment' ,
151+ comment : ' comment inside h2 tag ' ,
152+ } ,
153+ ] ,
154+ } ,
155+ ] ,
156+ } ,
157+ ] )
158+ t . equal ( html , HTML . stringify ( parsed ) )
159+
160+ html = '<!---->'
161+ parsed = HTML . parse ( html )
162+ t . deepEqual ( parsed , [
163+ {
164+ type : 'comment' ,
165+ comment : '' ,
166+ } ,
167+ ] )
168+ t . equal ( html , HTML . stringify ( parsed ) )
169+
170+ html =
171+ '<!---this comment starts with a hyphen b/c web developers love curveballs -->'
172+ parsed = HTML . parse ( html )
173+ t . deepEqual ( parsed , [
174+ {
175+ type : 'comment' ,
176+ comment :
177+ '-this comment starts with a hyphen b/c web developers love curveballs ' ,
178+ } ,
179+ ] )
180+ t . equal ( html , HTML . stringify ( parsed ) )
181+
58182 html = '<div>oh <strong>hello</strong> there! How are <span>you</span>?</div>'
59183 parsed = HTML . parse ( html )
60184
0 commit comments