@@ -1,3 +1,4 @@
1+{-# LANGUAGE LambdaCase #-}
12{-# LANGUAGE OverloadedStrings #-}
23{-# LANGUAGE CPP #-}
34{-# LANGUAGE ScopedTypeVariables #-}
@@ -352,7 +353,12 @@ readURI src = do
352353 Just "UTF-8" -> return $ UTF8.toText bs
353354 Just "ISO-8859-1" -> return $ T.pack $ B8.unpack bs
354355 Just charset -> throwError $ PandocUnsupportedCharsetError charset
355− Nothing -> return $ UTF8.toText bs
356+ Nothing -> liftIO $ -- try first as UTF-8, then as latin1
357+ E.catch (return $! UTF8.toText bs)
358+ (\case
359+ TSE.DecodeError{} ->
360+ return $ T.pack $ B8.unpack bs
361+ e -> E.throwIO e)
356362
357363readFile' :: MonadIO m => FilePath -> m BL.ByteString
358364readFile' "-" = liftIO BL.getContents