aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/UTF8.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/UTF8.hs')
-rw-r--r--src/Text/Pandoc/UTF8.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Text/Pandoc/UTF8.hs b/src/Text/Pandoc/UTF8.hs
index fb912a373..3dd61176c 100644
--- a/src/Text/Pandoc/UTF8.hs
+++ b/src/Text/Pandoc/UTF8.hs
@@ -43,14 +43,21 @@ import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn)
import System.IO (Handle)
import Control.Monad (liftM)
+bom :: B.ByteString
+bom = B.pack [0xEF, 0xBB, 0xBF]
+
+stripBOM :: B.ByteString -> B.ByteString
+stripBOM s | bom `B.isPrefixOf` s = B.drop 3 s
+stripBOM s = s
+
readFile :: FilePath -> IO String
-readFile = liftM toString . B.readFile
+readFile = liftM (toString . stripBOM) . B.readFile
writeFile :: FilePath -> String -> IO ()
writeFile f = B.writeFile f . fromString
getContents :: IO String
-getContents = liftM toString B.getContents
+getContents = liftM (toString . stripBOM) B.getContents
putStr :: String -> IO ()
putStr = B.putStr . fromString