Add support for UTF-8 with BOM encoding

encode() does not support utf-8 with BOM. Some text editors save in it. This fixes an error when trying to preview markdown files encoded with utf-8.