9
I’m making a tree to derive an HTML code. And I’m treating some particular cases. And one of those cases is just when someone opens a tag and doesn’t close it:
<html>
<body>
<div>
<div>
Hello World!!
</div>
Hello People!!
</body>
</html>
I have studied compilers at the university, but I don’t understand how the html interpretation works. In the case I have shown to close a </div>
before the </body>
. Opening the page and looking at the code I saw that the page inserts a </div>
before the </body
. But what made the page add the </div>
there and not before the text: Hello People!!
. It was the fact of </body>
be called and still the first <div>
not yet closed?
Code of the generated page:
<html><head></head><body>
<div>
<div>
Hello World!!
</div>
Hello People!!
</div></body></html>
Some specific name for the interpretation of html code?
Interestingly, I had already noticed that the Browser itself closes some tags, actually according to the W3C documentation several tags do not need to be closed, as the
<p>
etc, But as the browser "hit" where to close the div there after the text really can’t explain...– hugocsl
I’ve read about it somewhere. But I think modern browsers have a technology that automatically fixes several things.
– Sam
But I think the div closing before the
</body>
is because he disregards text knots. It makes more sense to close the element after all text nodes, because the texts are supposed to be part of the div.– Sam
Or rather, it will close the tag where it closes your father, in case, the body.
– Sam
Nor can I say exactly what the internal implementation, but keeping an open tag counter and seeing by opening and closing sequence, when reaching the body closure, the
</body>
the browser knows that there is a div to close and that it has to be closed before, and then chooses to close there because from now on it cannot be right– Isac