Safe removal of whitespace from a DOM