@@ -338,6 +338,10 @@ test('parse', function (t) {
338338 { type : 'text' , content : 'something' }
339339 ]
340340 } , {
341+ type : 'text' ,
342+ content : ' '
343+ } ,
344+ {
341345 type : 'tag' ,
342346 name : 'a' ,
343347 attrs : { } ,
@@ -347,8 +351,66 @@ test('parse', function (t) {
347351 type : 'text' , content : 'else '
348352 } ] , 'should handle text nodes in the middle of tags at the top-level' ) ;
349353
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>' ;
351377 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 } ) ;
352414 t . deepEqual ( parsed , [ {
353415 type : 'tag' ,
354416 name : 'div' ,
@@ -371,7 +433,7 @@ test('parse', function (t) {
371433 attrs : { } ,
372434 voidElement : false ,
373435 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 ' ) ;
375437
376438 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>' ;
377439 parsed = HTML . parse ( html ) ;
0 commit comments