@@ -292,6 +292,80 @@ test('parse', function (t) {
292
292
{ type : 'text' , content : ' 10 ' } ,
293
293
]
294
294
} ] , 'should not give voidElements children' ) ;
295
+
296
+ html = '<div></div>\n' ;
297
+ parsed = HTML . parse ( html ) ;
298
+ t . deepEqual ( parsed , [ {
299
+ type : 'tag' ,
300
+ name : 'div' ,
301
+ attrs : { } ,
302
+ voidElement : false ,
303
+ children : [ ]
304
+ } ] , 'should not explode on trailing whitespace' ) ;
305
+
306
+ html = '<div>Hi</div> There ' ;
307
+ parsed = HTML . parse ( html ) ;
308
+ t . deepEqual ( parsed , [ {
309
+ type : 'tag' ,
310
+ name : 'div' ,
311
+ attrs : { } ,
312
+ voidElement : false ,
313
+ children : [
314
+ { type : 'text' , content : 'Hi' }
315
+ ]
316
+ } , {
317
+ type : 'text' , content : ' There '
318
+ } ] , 'should handle trailing text nodes at the top-level' ) ;
319
+
320
+ html = '<div>Hi</div> There <span>something</span> <a></a>else ' ;
321
+ parsed = HTML . parse ( html ) ;
322
+ t . deepEqual ( parsed , [ {
323
+ type : 'tag' ,
324
+ name : 'div' ,
325
+ attrs : { } ,
326
+ voidElement : false ,
327
+ children : [
328
+ { type : 'text' , content : 'Hi' }
329
+ ]
330
+ } , {
331
+ type : 'text' , content : ' There '
332
+ } , {
333
+ type : 'tag' ,
334
+ name : 'span' ,
335
+ attrs : { } ,
336
+ voidElement : false ,
337
+ children : [
338
+ { type : 'text' , content : 'something' }
339
+ ]
340
+ } , {
341
+ type : 'tag' ,
342
+ name : 'a' ,
343
+ attrs : { } ,
344
+ voidElement : false ,
345
+ children : [ ]
346
+ } , {
347
+ type : 'text' , content : 'else '
348
+ } ] , 'should handle text nodes in the middle of tags at the top-level' ) ;
349
+
350
+ html = '<div>Hi</div>\n\n <span>There</span> \t ' ;
351
+ parsed = HTML . parse ( html ) ;
352
+ t . deepEqual ( parsed , [ {
353
+ type : 'tag' ,
354
+ name : 'div' ,
355
+ attrs : { } ,
356
+ voidElement : false ,
357
+ children : [
358
+ { type : 'text' , content : 'Hi' }
359
+ ]
360
+ } , {
361
+ type : 'tag' ,
362
+ name : 'span' ,
363
+ attrs : { } ,
364
+ voidElement : false ,
365
+ children : [
366
+ { type : 'text' , content : 'There' }
367
+ ]
368
+ } ] , 'should remove text nodes that are nothing but whitespace' ) ;
295
369
t . end ( ) ;
296
370
} ) ;
297
371
0 commit comments