@@ -338,6 +338,10 @@ test('parse', function (t) {
338
338
{ type : 'text' , content : 'something' }
339
339
]
340
340
} , {
341
+ type : 'text' ,
342
+ content : ' '
343
+ } ,
344
+ {
341
345
type : 'tag' ,
342
346
name : 'a' ,
343
347
attrs : { } ,
@@ -347,8 +351,66 @@ test('parse', function (t) {
347
351
type : 'text' , content : 'else '
348
352
} ] , 'should handle text nodes in the middle of tags at the top-level' ) ;
349
353
350
- html = '<div>Hi</div>\n\n <span>There</span> \t <iframe>\n\t</iframe>' ;
354
+ html = '\n<div> <span>Hi!</span> </div>\n' ;
355
+ parsed = HTML . parse ( html ) ;
356
+ t . deepEqual ( parsed , [ {
357
+ type : 'tag' ,
358
+ name : 'div' ,
359
+ attrs : { } ,
360
+ voidElement : false ,
361
+ children : [
362
+ { type : 'text' , content : ' ' } ,
363
+ {
364
+ type : 'tag' ,
365
+ name : 'span' ,
366
+ attrs : { } ,
367
+ voidElement : false ,
368
+ children : [
369
+ { type : 'text' , content : 'Hi!' }
370
+ ]
371
+ } ,
372
+ { type : 'text' , content : ' ' }
373
+ ]
374
+ } ] , 'should trim whitespace from the beginning and end of the parsed nodes' ) ;
375
+
376
+ html = '<div>Hi</div>\n\n <span>There</span> \t <div>\n\t</div>' ;
351
377
parsed = HTML . parse ( html ) ;
378
+ t . deepEqual ( parsed , [ {
379
+ type : 'tag' ,
380
+ name : 'div' ,
381
+ attrs : { } ,
382
+ voidElement : false ,
383
+ children : [
384
+ { type : 'text' , content : 'Hi' }
385
+ ]
386
+ } , {
387
+ type : 'text' ,
388
+ content : ' '
389
+ } ,
390
+ {
391
+ type : 'tag' ,
392
+ name : 'span' ,
393
+ attrs : { } ,
394
+ voidElement : false ,
395
+ children : [
396
+ { type : 'text' , content : 'There' }
397
+ ]
398
+ } , {
399
+ type : 'text' ,
400
+ content : ' '
401
+ } , {
402
+ type : 'tag' ,
403
+ name : 'div' ,
404
+ attrs : { } ,
405
+ voidElement : false ,
406
+ children : [
407
+ { type : 'text' , content : ' ' }
408
+ ]
409
+ } ] , 'should collapse whitespace' ) ;
410
+ // See https://www.w3.org/TR/html4/struct/text.html#h-9.1
411
+
412
+ html = '<div>Hi</div>\n\n <span>There</span> \t <iframe>\n\t</iframe>' ;
413
+ parsed = HTML . parse ( html , { ignoreWhitespace : true } ) ;
352
414
t . deepEqual ( parsed , [ {
353
415
type : 'tag' ,
354
416
name : 'div' ,
@@ -371,7 +433,7 @@ test('parse', function (t) {
371
433
attrs : { } ,
372
434
voidElement : false ,
373
435
children : [ ]
374
- } ] , 'should remove text nodes that are nothing but whitespace' ) ;
436
+ } ] , 'should remove text nodes that are nothing but whitespace if the ignoreWhitespace option is passed ' ) ;
375
437
376
438
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>' ;
377
439
parsed = HTML . parse ( html ) ;
0 commit comments