replace unencodeable codepoints with html entities

fixes #562 and #285