Encode HTML as string when necessary