Improved the way to get the HTML of a element

This handles better the case of non-strict HTML.