Documents don't really work in term of HTML tags. As soon as parsing ends, there is no more HTML, only the DOM structure, which on demand can be translated back to HTML.
In your example the parser looks at the string Sam </strong> and <strong> Susan
, sees that it's incomplete and tries to correct it, so you get Sam and <strong> Susan</strong>
.
I suppose it could dump the DOM to HTML, replace the innerHTML
literally and re-parse the whole thing, but that would be a lot slower with insignificant benefits.