Fix encoding errors when writing to HTML tidy.