git.iko.soy/typeable/pandoc
on master help sign in
Revert "Use local encoding for input/output rather than forcing UTF8."
f673336John MacFarlane
src/Text/Pandoc/Parsing.hs+2−1
@@ -146,6 +146,7 @@ where
146import Text.Pandoc.Definition
146import Text.Pandoc.Definition
147import Text.Pandoc.Options
147import Text.Pandoc.Options
148import Text.Pandoc.Builder (Blocks)
148import Text.Pandoc.Builder (Blocks)
149+import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
149import Text.Parsec
150import Text.Parsec
150import Text.Parsec.Pos (newPos)
151import Text.Parsec.Pos (newPos)
151import Data.Char ( toLower, toUpper, ord, isAscii, isAlphaNum, isDigit, isPunctuation )
152import Data.Char ( toLower, toUpper, ord, isAscii, isAlphaNum, isDigit, isPunctuation )
@@ -707,7 +708,7 @@ readWith parser state input =
707testStringWith :: (Show a) => Parser [Char] ParserState a
708testStringWith :: (Show a) => Parser [Char] ParserState a
708 -> String
709 -> String
709 -> IO ()
710 -> IO ()
710−testStringWith parser str = putStrLn $ show $
711+testStringWith parser str = UTF8.putStrLn $ show $
711 readWith parser defaultParserState str
712 readWith parser defaultParserState str
712
713
713-- | Parsing options.
714-- | Parsing options.
src/pandoc.hs+11−11
@@ -363,7 +363,7 @@ options =
363 , Option "H" ["include-in-header"]
363 , Option "H" ["include-in-header"]
364 (ReqArg
364 (ReqArg
365 (\arg opt -> do
365 (\arg opt -> do
366− text <- readFile arg
366+ text <- UTF8.readFile arg
367 -- add new ones to end, so they're included in order specified
367 -- add new ones to end, so they're included in order specified
368 let newvars = optVariables opt ++ [("header-includes",text)]
368 let newvars = optVariables opt ++ [("header-includes",text)]
369 return opt { optVariables = newvars,
369 return opt { optVariables = newvars,
@@ -374,7 +374,7 @@ options =
374 , Option "B" ["include-before-body"]
374 , Option "B" ["include-before-body"]
375 (ReqArg
375 (ReqArg
376 (\arg opt -> do
376 (\arg opt -> do
377− text <- readFile arg
377+ text <- UTF8.readFile arg
378 -- add new ones to end, so they're included in order specified
378 -- add new ones to end, so they're included in order specified
379 let newvars = optVariables opt ++ [("include-before",text)]
379 let newvars = optVariables opt ++ [("include-before",text)]
380 return opt { optVariables = newvars,
380 return opt { optVariables = newvars,
@@ -385,7 +385,7 @@ options =
385 , Option "A" ["include-after-body"]
385 , Option "A" ["include-after-body"]
386 (ReqArg
386 (ReqArg
387 (\arg opt -> do
387 (\arg opt -> do
388− text <- readFile arg
388+ text <- UTF8.readFile arg
389 -- add new ones to end, so they're included in order specified
389 -- add new ones to end, so they're included in order specified
390 let newvars = optVariables opt ++ [("include-after",text)]
390 let newvars = optVariables opt ++ [("include-after",text)]
391 return opt { optVariables = newvars,
391 return opt { optVariables = newvars,
@@ -528,7 +528,7 @@ options =
528 , Option "" ["epub-stylesheet"]
528 , Option "" ["epub-stylesheet"]
529 (ReqArg
529 (ReqArg
530 (\arg opt -> do
530 (\arg opt -> do
531− text <- readFile arg
531+ text <- UTF8.readFile arg
532 return opt { optEPUBStylesheet = Just text })
532 return opt { optEPUBStylesheet = Just text })
533 "FILENAME")
533 "FILENAME")
534 "" -- "Path of epub.css"
534 "" -- "Path of epub.css"
@@ -544,7 +544,7 @@ options =
544 , Option "" ["epub-metadata"]
544 , Option "" ["epub-metadata"]
545 (ReqArg
545 (ReqArg
546 (\arg opt -> do
546 (\arg opt -> do
547− text <- readFile arg
547+ text <- UTF8.readFile arg
548 return opt { optEPUBMetadata = text })
548 return opt { optEPUBMetadata = text })
549 "FILENAME")
549 "FILENAME")
550 "" -- "Path of epub metadata file"
550 "" -- "Path of epub metadata file"
@@ -756,7 +756,7 @@ defaultWriterName x =
756main :: IO ()
756main :: IO ()
757main = do
757main = do
758
758
759− rawArgs <- liftM (map UTF8.decodeArg) getArgs
759+ rawArgs <- liftM (map decodeArg) getArgs
760 prg <- getProgName
760 prg <- getProgName
761 let compatMode = (prg == "hsmarkdown")
761 let compatMode = (prg == "hsmarkdown")
762
762
@@ -888,7 +888,7 @@ main = do
888 let tp' = case takeExtension tp of
888 let tp' = case takeExtension tp of
889 "" -> tp <.> format
889 "" -> tp <.> format
890 _ -> tp
890 _ -> tp
891− E.catch (readFile tp')
891+ E.catch (UTF8.readFile tp')
892 (\e -> if isDoesNotExistError e
892 (\e -> if isDoesNotExistError e
893 then E.catch
893 then E.catch
894 (readDataFile datadir $
894 (readDataFile datadir $
@@ -982,11 +982,11 @@ main = do
982
982
983 let readSources [] = mapM readSource ["-"]
983 let readSources [] = mapM readSource ["-"]
984 readSources srcs = mapM readSource srcs
984 readSources srcs = mapM readSource srcs
985− readSource "-" = getContents
985+ readSource "-" = UTF8.getContents
986 readSource src = case parseURI src of
986 readSource src = case parseURI src of
987 Just u | uriScheme u `elem` ["http:","https:"] ->
987 Just u | uriScheme u `elem` ["http:","https:"] ->
988 readURI u
988 readURI u
989− _ -> readFile src
989+ _ -> UTF8.readFile src
990 readURI uri = simpleHTTP (mkRequest GET uri) >>= getResponseBody >>=
990 readURI uri = simpleHTTP (mkRequest GET uri) >>= getResponseBody >>=
991 return . toString -- treat all as UTF8
991 return . toString -- treat all as UTF8
992
992
@@ -1026,8 +1026,8 @@ main = do
1026 writeBinary = B.writeFile (UTF8.encodePath outputFile)
1026 writeBinary = B.writeFile (UTF8.encodePath outputFile)
1027
1027
1028 let writerFn :: FilePath -> String -> IO ()
1028 let writerFn :: FilePath -> String -> IO ()
1029− writerFn "-" = putStr
1029+ writerFn "-" = UTF8.putStr
1030− writerFn f = writeFile (UTF8.encodePath f)
1030+ writerFn f = UTF8.writeFile f
1031
1031
1032 case getWriter writerName' of
1032 case getWriter writerName' of
1033 Left e -> err 9 e
1033 Left e -> err 9 e