Improved handling of non well-formed HTML files when using fragments