If I have something like: <html> <head><script> function foo() { alert(document.documentElement.innerHTML); } </script></head> <body>World</body> </html> I see that the whitespace after </head> and before <body> is lost. See the attached test case.
Created attachment 33671 [details] test case
Are you sure it's lost? I think the significant whitespace following the </head> causes the parser to have to open a <body> implicitly.... so the whitespace is probably just inside the <body> instead...
That's a sensible explanation, but from the viewpoint of roundtripping HTML, it would be really nice if that *didn't* happen... :)
Upon investigation it seems that this is not the case. The whitespace is actually lost.
Is this significant whitespace in your test? I'm not absolutely sure, but I think that you'd need an XML document with xml:space="preserve" to make this whitespace significant.
Regardless of whether it's significant, when making tools that work with HTML the user wants to round-trip, this behavior is undesirable.
This behavior is covered by the HTML Standard.