Fix DOM exception being thrown by htmlToFragment