Prevent infinite loop in highlight_diff()

by better structuring the code, and adding assertions about the expected state
of the input.
Treat html entities correctly
Fallback for incorrectly detected charsets

If a bytestring cannotd be decoded using the guessed charset,
try decoding it using some default charsets (utf8,latin).