@@ -45,14 +45,7 @@ import Data.Char ( toLower, isDigit )
4545import Data.List ( intercalate, isSuffixOf )
4646import System.Directory ( getAppUserDataDirectory )
4747import System.IO ( stdout, stderr )
48−-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
49−-- So we use System.IO.UTF8 only if we have an earlier version
50−#if MIN_VERSION_base(4,2,0)
51−import System.IO ( hPutStr, hPutStrLn )
52−#else
53−import Prelude hiding ( putStr, putStrLn, writeFile, readFile, getContents )
54−import System.IO.UTF8
55−#endif
48+import qualified Text.Pandoc.UTF8 as UTF8
5649#ifdef _CITEPROC
5750import Text.CSL
5851import Text.Pandoc.Biblio
@@ -344,7 +337,7 @@ options =
344337 "references" -> return ReferenceObfuscation
345338 "javascript" -> return JavascriptObfuscation
346339 "none" -> return NoObfuscation
347− _ -> hPutStrLn stderr ("Error: Unknown obfuscation method: " ++ arg) >>
340+ _ -> UTF8.hPutStrLn stderr ("Error: Unknown obfuscation method: " ++ arg) >>
348341 exitWith (ExitFailure 6)
349342 return opt { optEmailObfuscation = method })
350343 "none|javascript|references")
@@ -378,7 +371,7 @@ options =
378371 return opt{ optTransforms =
379372 headerShift shift : oldTransforms }
380373 else do
381− hPutStrLn stderr $ "base-header-level must be a number >= 1"
374+ UTF8.hPutStrLn stderr $ "base-header-level must be a number >= 1"
382375 exitWith $ ExitFailure 19)
383376 "LEVEL")
384377 "" -- "Headers base level"
@@ -386,7 +379,7 @@ options =
386379 , Option "" ["template"]
387380 (ReqArg
388381 (\arg opt -> do
389− text <- readFile arg
382+ text <- UTF8.readFile arg
390383 return opt{ optTemplate = text,
391384 optStandalone = True })
392385 "FILENAME")
@@ -400,7 +393,7 @@ options =
400393 let newvars = optVariables opt ++ [(k,v)]
401394 return opt{ optVariables = newvars }
402395 _ -> do
403− hPutStrLn stderr $ "Could not parse `" ++ arg ++ "' as a key/value pair (k=v or k:v)"
396+ UTF8.hPutStrLn stderr $ "Could not parse `" ++ arg ++ "' as a key/value pair (k=v or k:v)"
404397 exitWith $ ExitFailure 17)
405398 "FILENAME")
406399 "" -- "Use custom template"
@@ -418,7 +411,7 @@ options =
418411 , Option "H" ["include-in-header"]
419412 (ReqArg
420413 (\arg opt -> do
421− text <- readFile arg
414+ text <- UTF8.readFile arg
422415 -- add new ones to end, so they're included in order specified
423416 let newvars = optVariables opt ++ [("header-includes",text)]
424417 return opt { optVariables = newvars,
@@ -429,7 +422,7 @@ options =
429422 , Option "B" ["include-before-body"]
430423 (ReqArg
431424 (\arg opt -> do
432− text <- readFile arg
425+ text <- UTF8.readFile arg
433426 -- add new ones to end, so they're included in order specified
434427 let newvars = optVariables opt ++ [("include-before",text)]
435428 return opt { optVariables = newvars,
@@ -440,7 +433,7 @@ options =
440433 , Option "A" ["include-after-body"]
441434 (ReqArg
442435 (\arg opt -> do
443− text <- readFile arg
436+ text <- UTF8.readFile arg
444437 -- add new ones to end, so they're included in order specified
445438 let newvars = optVariables opt ++ [("include-after",text)]
446439 return opt { optVariables = newvars,
@@ -451,7 +444,7 @@ options =
451444 , Option "C" ["custom-header"]
452445 (ReqArg
453446 (\arg opt -> do
454− text <- readFile arg
447+ text <- UTF8.readFile arg
455448 let newVars = ("legacy-header", text) : optVariables opt
456449 return opt { optVariables = newVars
457450 , optStandalone = True })
@@ -479,7 +472,7 @@ options =
479472 (\arg _ -> do
480473 templ <- getDefaultTemplate Nothing arg
481474 case templ of
482− Right t -> hPutStr stdout t
475+ Right t -> UTF8.hPutStr stdout t
483476 Left e -> error $ show e
484477 exitWith ExitSuccess)
485478 "FORMAT")
@@ -521,7 +514,7 @@ options =
521514 (NoArg
522515 (\_ -> do
523516 prg <- getProgName
524− hPutStrLn stdout (prg ++ " " ++ pandocVersion ++ compileInfo ++
517+ UTF8.hPutStrLn stdout (prg ++ " " ++ pandocVersion ++ compileInfo ++
525518 copyrightMessage)
526519 exitWith ExitSuccess ))
527520 "" -- "Print version"
@@ -530,7 +523,7 @@ options =
530523 (NoArg
531524 (\_ -> do
532525 prg <- getProgName
533− hPutStr stdout (usageMessage prg options)
526+ UTF8.hPutStr stdout (usageMessage prg options)
534527 exitWith ExitSuccess ))
535528 "" -- "Show help"
536529 ]
@@ -603,8 +596,8 @@ main = do
603596
604597 unless (null errors) $
605598 do name <- getProgName
606− mapM_ (\e -> hPutStr stderr (name ++ ": ") >> hPutStr stderr e) errors
607− hPutStrLn stderr $ "Try " ++ name ++ " --help for more information."
599+ mapM_ (\e -> UTF8.hPutStr stderr (name ++ ": ") >> UTF8.hPutStr stderr e) errors
600+ UTF8.hPutStrLn stderr $ "Try " ++ name ++ " --help for more information."
608601 exitWith $ ExitFailure 2
609602
610603 let defaultOpts' = if compatMode
@@ -653,13 +646,13 @@ main = do
653646 } = opts
654647
655648 when dumpArgs $
656− do hPutStrLn stdout outputFile
657− mapM_ (\arg -> hPutStrLn stdout arg) args
649+ do UTF8.hPutStrLn stdout outputFile
650+ mapM_ (\arg -> UTF8.hPutStrLn stdout arg) args
658651 exitWith ExitSuccess
659652
660653 -- warn about deprecated options
661654 case lookup "legacy-header" variables of
662− Just _ -> hPutStrLn stderr $
655+ Just _ -> UTF8.hPutStrLn stderr $
663656 "Warning: The -C/--custom-header is deprecated.\n" ++
664657 "Please transition to using --template instead."
665658 Nothing -> return ()
@@ -765,7 +758,7 @@ main = do
765758 writerIdentifierPrefix = idPrefix }
766759
767760 when (isNonTextOutput writerName' && outputFile == "-") $
768− do hPutStrLn stderr ("Error: Cannot write " ++ writerName ++ " output to stdout.\n" ++
761+ do UTF8.hPutStrLn stderr ("Error: Cannot write " ++ writerName ++ " output to stdout.\n" ++
769762 "Specify an output file using the -o option.")
770763 exitWith $ ExitFailure 5
771764
@@ -775,10 +768,10 @@ main = do
775768
776769 let readSources [] = mapM readSource ["-"]
777770 readSources srcs = mapM readSource srcs
778− readSource "-" = getContents
771+ readSource "-" = UTF8.getContents
779772 readSource src = case parseURI src of
780773 Just u -> readURI u
781− Nothing -> readFile src
774+ Nothing -> UTF8.readFile src
782775 readURI uri = simpleHTTP (mkRequest GET uri) >>= getResponseBody >>=
783776 return . toString -- treat all as UTF8
784777
@@ -800,5 +793,5 @@ main = do
800793 case writerName' of
801794 "odt" -> saveOpenDocumentAsODT datadir outputFile sourceDirRelative referenceODT writerOutput
802795 _ -> if outputFile == "-"
803− then putStr writerOutput
804− else writeFile outputFile writerOutput
796+ then UTF8.putStr writerOutput
797+ else UTF8.writeFile outputFile writerOutput