git.iko.soy/typeable/pandoc
on master help sign in
Don't encode/decode file paths if base >= 4.5.
cc39c31John MacFarlane
src/Text/Pandoc/UTF8.hs+16−6
@@ -39,21 +39,25 @@ module Text.Pandoc.UTF8 ( readFile
39
39
40where
40where
41
41
42+#if MIN_VERSION_base(4,5,0)
43+#else
44+import Codec.Binary.UTF8.String (encodeString)
45+#endif
46+
42#if MIN_VERSION_base(4,2,0)
47#if MIN_VERSION_base(4,2,0)
43
48
44import System.IO hiding (readFile, writeFile, getContents,
49import System.IO hiding (readFile, writeFile, getContents,
45 putStr, putStrLn, hPutStr, hPutStrLn, hGetContents)
50 putStr, putStrLn, hPutStr, hPutStrLn, hGetContents)
46import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn )
51import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn )
47−import Codec.Binary.UTF8.String (encodeString)
48import qualified System.IO as IO
52import qualified System.IO as IO
49
53
50readFile :: FilePath -> IO String
54readFile :: FilePath -> IO String
51readFile f = do
55readFile f = do
52− h <- openFile (encodeString f) ReadMode
56+ h <- openFile (encodePath f) ReadMode
53 hGetContents h
57 hGetContents h
54
58
55writeFile :: FilePath -> String -> IO ()
59writeFile :: FilePath -> String -> IO ()
56−writeFile f s = withFile (encodeString f) WriteMode $ \h -> hPutStr h s
60+writeFile f s = withFile (encodePath f) WriteMode $ \h -> hPutStr h s
57
61
58getContents :: IO String
62getContents :: IO String
59getContents = hGetContents stdin
63getContents = hGetContents stdin
@@ -76,7 +80,6 @@ hGetContents h = hSetEncoding h utf8_bom >> IO.hGetContents h
76#else
80#else
77
81
78import qualified Data.ByteString as B
82import qualified Data.ByteString as B
79−import Codec.Binary.UTF8.String (encodeString)
80import Data.ByteString.UTF8 (toString, fromString)
83import Data.ByteString.UTF8 (toString, fromString)
81import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn)
84import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn)
82import System.IO (Handle)
85import System.IO (Handle)
@@ -91,10 +94,10 @@ stripBOM s | bom `B.isPrefixOf` s = B.drop 3 s
91stripBOM s = s
94stripBOM s = s
92
95
93readFile :: FilePath -> IO String
96readFile :: FilePath -> IO String
94−readFile = liftM (toString . stripBOM) . B.readFile . encodeString
97+readFile = liftM (toString . stripBOM) . B.readFile . encodePath
95
98
96writeFile :: FilePath -> String -> IO ()
99writeFile :: FilePath -> String -> IO ()
97−writeFile f = B.writeFile (encodeString f) . fromString
100+writeFile f = B.writeFile (encodePath f) . fromString
98
101
99getContents :: IO String
102getContents :: IO String
100getContents = liftM (toString . stripBOM) B.getContents
103getContents = liftM (toString . stripBOM) B.getContents
@@ -115,3 +118,10 @@ hPutStrLn :: Handle -> String -> IO ()
115hPutStrLn h s = hPutStr h (s ++ "\n")
118hPutStrLn h s = hPutStr h (s ++ "\n")
116
119
117#endif
120#endif
121+
122+encodePath :: FilePath -> FilePath
123+#if MIN_VERSION_base(4,5,0)
124+encodePath = id
125+#else
126+encodePath = encodeString
127+#endif
src/pandoc.hs+17−3
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1{-
2{-
2Copyright (C) 2006-2012 John MacFarlane <jgm@berkeley.edu>
3Copyright (C) 2006-2012 John MacFarlane <jgm@berkeley.edu>
3
4
@@ -56,8 +57,21 @@ import Network.HTTP (simpleHTTP, mkRequest, getResponseBody, RequestMethod(..))
56import Network.URI (parseURI, isURI, URI(..))
57import Network.URI (parseURI, isURI, URI(..))
57import qualified Data.ByteString.Lazy as B
58import qualified Data.ByteString.Lazy as B
58import Data.ByteString.Lazy.UTF8 (toString )
59import Data.ByteString.Lazy.UTF8 (toString )
59−import Codec.Binary.UTF8.String (decodeString, encodeString)
60import Text.CSL.Reference (Reference(..))
60import Text.CSL.Reference (Reference(..))
61+#if MIN_VERSION_base(4,5,0)
62+#else
63+import Codec.Binary.UTF8.String (decodeString, encodeString)
64+#endif
65+
66+encodePath, decodeArg :: FilePath -> FilePath
67+#if MIN_VERSION_base(4,5,0)
68+encodePath = id
69+decodeArg = id
70+#else
71+encodePath = encodeString
72+decodeArg = decodeString
73+#endif
74+
61
75
62copyrightMessage :: String
76copyrightMessage :: String
63copyrightMessage = "\nCopyright (C) 2006-2012 John MacFarlane\n" ++
77copyrightMessage = "\nCopyright (C) 2006-2012 John MacFarlane\n" ++
@@ -745,7 +759,7 @@ defaultWriterName x =
745main :: IO ()
759main :: IO ()
746main = do
760main = do
747
761
748− rawArgs <- liftM (map decodeString) getArgs
762+ rawArgs <- liftM (map decodeArg) getArgs
749 prg <- getProgName
763 prg <- getProgName
750 let compatMode = (prg == "hsmarkdown")
764 let compatMode = (prg == "hsmarkdown")
751
765
@@ -1023,7 +1037,7 @@ main = do
1023 else return doc1
1037 else return doc1
1024
1038
1025 let writeBinary :: B.ByteString -> IO ()
1039 let writeBinary :: B.ByteString -> IO ()
1026− writeBinary = B.writeFile (encodeString outputFile)
1040+ writeBinary = B.writeFile (encodePath outputFile)
1027
1041
1028 let writerFn :: FilePath -> String -> IO ()
1042 let writerFn :: FilePath -> String -> IO ()
1029 writerFn "-" = UTF8.putStr
1043 writerFn "-" = UTF8.putStr