@@ -45,14 +45,7 @@ import Data.Char ( toLower, isDigit )
45import Data.List ( intercalate, isSuffixOf )
45import Data.List ( intercalate, isSuffixOf )
46import System.Directory ( getAppUserDataDirectory )
46import System.Directory ( getAppUserDataDirectory )
47import System.IO ( stdout, stderr )
47import System.IO ( stdout, stderr )
48−-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
48+import qualified Text.Pandoc.UTF8 as UTF8
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 )
53−import Prelude hiding ( putStr, putStrLn, writeFile, readFile, getContents )
56#ifdef _CITEPROC
49#ifdef _CITEPROC
57import Text.CSL
50import Text.CSL
58import Text.Pandoc.Biblio
51import Text.Pandoc.Biblio
@@ -344,7 +337,7 @@ options =
344 "references" -> return ReferenceObfuscation
337 "references" -> return ReferenceObfuscation
345 "javascript" -> return JavascriptObfuscation
338 "javascript" -> return JavascriptObfuscation
346 "none" -> return NoObfuscation
339 "none" -> return NoObfuscation
347− _ -> hPutStrLn stderr ("Error: Unknown obfuscation method: " ++ arg) >>
340+ _ -> UTF8.hPutStrLn stderr ("Error: Unknown obfuscation method: " ++ arg) >>
348 exitWith (ExitFailure 6)
341 exitWith (ExitFailure 6)
349 return opt { optEmailObfuscation = method })
342 return opt { optEmailObfuscation = method })
350 "none|javascript|references")
343 "none|javascript|references")
@@ -378,7 +371,7 @@ options =
378 return opt{ optTransforms =
371 return opt{ optTransforms =
379 headerShift shift : oldTransforms }
372 headerShift shift : oldTransforms }
381− hPutStrLn stderr $ "base-header-level must be a number >= 1"
374+ UTF8.hPutStrLn stderr $ "base-header-level must be a number >= 1"
382 exitWith $ ExitFailure 19)
375 exitWith $ ExitFailure 19)
384 "" -- "Headers base level"
377 "" -- "Headers base level"
@@ -386,7 +379,7 @@ options =
386 , Option "" ["template"]
379 , Option "" ["template"]
388 (\arg opt -> do
381 (\arg opt -> do
389− text <- readFile arg
382+ text <- UTF8.readFile arg
390 return opt{ optTemplate = text,
383 return opt{ optTemplate = text,
391 optStandalone = True })
384 optStandalone = True })
392 "FILENAME")
385 "FILENAME")
@@ -400,7 +393,7 @@ options =
400 let newvars = optVariables opt ++ [(k,v)]
393 let newvars = optVariables opt ++ [(k,v)]
401 return opt{ optVariables = newvars }
394 return opt{ optVariables = newvars }
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)"
404 exitWith $ ExitFailure 17)
397 exitWith $ ExitFailure 17)
405 "FILENAME")
398 "FILENAME")
406 "" -- "Use custom template"
399 "" -- "Use custom template"
@@ -418,7 +411,7 @@ options =
418 , Option "H" ["include-in-header"]
411 , Option "H" ["include-in-header"]
420 (\arg opt -> do
413 (\arg opt -> do
421− text <- readFile arg
414+ text <- UTF8.readFile arg
422 -- add new ones to end, so they're included in order specified
415 -- add new ones to end, so they're included in order specified
423 let newvars = optVariables opt ++ [("header-includes",text)]
416 let newvars = optVariables opt ++ [("header-includes",text)]
424 return opt { optVariables = newvars,
417 return opt { optVariables = newvars,
@@ -429,7 +422,7 @@ options =
429 , Option "B" ["include-before-body"]
422 , Option "B" ["include-before-body"]
431 (\arg opt -> do
424 (\arg opt -> do
432− text <- readFile arg
425+ text <- UTF8.readFile arg
433 -- add new ones to end, so they're included in order specified
426 -- add new ones to end, so they're included in order specified
434 let newvars = optVariables opt ++ [("include-before",text)]
427 let newvars = optVariables opt ++ [("include-before",text)]
435 return opt { optVariables = newvars,
428 return opt { optVariables = newvars,
@@ -440,7 +433,7 @@ options =
440 , Option "A" ["include-after-body"]
433 , Option "A" ["include-after-body"]
442 (\arg opt -> do
435 (\arg opt -> do
443− text <- readFile arg
436+ text <- UTF8.readFile arg
444 -- add new ones to end, so they're included in order specified
437 -- add new ones to end, so they're included in order specified
445 let newvars = optVariables opt ++ [("include-after",text)]
438 let newvars = optVariables opt ++ [("include-after",text)]
446 return opt { optVariables = newvars,
439 return opt { optVariables = newvars,
@@ -451,7 +444,7 @@ options =
451 , Option "C" ["custom-header"]
444 , Option "C" ["custom-header"]
453 (\arg opt -> do
446 (\arg opt -> do
454− text <- readFile arg
447+ text <- UTF8.readFile arg
455 let newVars = ("legacy-header", text) : optVariables opt
448 let newVars = ("legacy-header", text) : optVariables opt
456 return opt { optVariables = newVars
449 return opt { optVariables = newVars
457 , optStandalone = True })
450 , optStandalone = True })
@@ -479,7 +472,7 @@ options =
479 (\arg _ -> do
472 (\arg _ -> do
480 templ <- getDefaultTemplate Nothing arg
473 templ <- getDefaultTemplate Nothing arg
481 case templ of
474 case templ of
482− Right t -> hPutStr stdout t
475+ Right t -> UTF8.hPutStr stdout t
483 Left e -> error $ show e
476 Left e -> error $ show e
484 exitWith ExitSuccess)
477 exitWith ExitSuccess)
485 "FORMAT")
478 "FORMAT")
@@ -521,7 +514,7 @@ options =
522 (\_ -> do
515 (\_ -> do
523 prg <- getProgName
516 prg <- getProgName
524− hPutStrLn stdout (prg ++ " " ++ pandocVersion ++ compileInfo ++
517+ UTF8.hPutStrLn stdout (prg ++ " " ++ pandocVersion ++ compileInfo ++
525 copyrightMessage)
518 copyrightMessage)
526 exitWith ExitSuccess ))
519 exitWith ExitSuccess ))
527 "" -- "Print version"
520 "" -- "Print version"
@@ -530,7 +523,7 @@ options =
531 (\_ -> do
524 (\_ -> do
532 prg <- getProgName
525 prg <- getProgName
533− hPutStr stdout (usageMessage prg options)
526+ UTF8.hPutStr stdout (usageMessage prg options)
534 exitWith ExitSuccess ))
527 exitWith ExitSuccess ))
535 "" -- "Show help"
528 "" -- "Show help"
@@ -603,8 +596,8 @@ main = do
604 unless (null errors) $
597 unless (null errors) $
605 do name <- getProgName
598 do name <- getProgName
606− mapM_ (\e -> hPutStr stderr (name ++ ": ") >> hPutStr stderr e) errors
599+ mapM_ (\e -> UTF8.hPutStr stderr (name ++ ": ") >> UTF8.hPutStr stderr e) errors
607− hPutStrLn stderr $ "Try " ++ name ++ " --help for more information."
600+ UTF8.hPutStrLn stderr $ "Try " ++ name ++ " --help for more information."
608 exitWith $ ExitFailure 2
601 exitWith $ ExitFailure 2
610 let defaultOpts' = if compatMode
603 let defaultOpts' = if compatMode
@@ -653,13 +646,13 @@ main = do
655 when dumpArgs $
648 when dumpArgs $
656− do hPutStrLn stdout outputFile
649+ do UTF8.hPutStrLn stdout outputFile
657− mapM_ (\arg -> hPutStrLn stdout arg) args
650+ mapM_ (\arg -> UTF8.hPutStrLn stdout arg) args
658 exitWith ExitSuccess
651 exitWith ExitSuccess
660 -- warn about deprecated options
653 -- warn about deprecated options
661 case lookup "legacy-header" variables of
654 case lookup "legacy-header" variables of
662− Just _ -> hPutStrLn stderr $
655+ Just _ -> UTF8.hPutStrLn stderr $
663 "Warning: The -C/--custom-header is deprecated.\n" ++
656 "Warning: The -C/--custom-header is deprecated.\n" ++
664 "Please transition to using --template instead."
657 "Please transition to using --template instead."
665 Nothing -> return ()
658 Nothing -> return ()
@@ -765,7 +758,7 @@ main = do
765 writerIdentifierPrefix = idPrefix }
758 writerIdentifierPrefix = idPrefix }
767 when (isNonTextOutput writerName' && outputFile == "-") $
760 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" ++
769 "Specify an output file using the -o option.")
762 "Specify an output file using the -o option.")
770 exitWith $ ExitFailure 5
763 exitWith $ ExitFailure 5
@@ -775,10 +768,10 @@ main = do
776 let readSources [] = mapM readSource ["-"]
769 let readSources [] = mapM readSource ["-"]
777 readSources srcs = mapM readSource srcs
770 readSources srcs = mapM readSource srcs
778− readSource "-" = getContents
771+ readSource "-" = UTF8.getContents
779 readSource src = case parseURI src of
772 readSource src = case parseURI src of
780 Just u -> readURI u
773 Just u -> readURI u
781− Nothing -> readFile src
774+ Nothing -> UTF8.readFile src
782 readURI uri = simpleHTTP (mkRequest GET uri) >>= getResponseBody >>=
775 readURI uri = simpleHTTP (mkRequest GET uri) >>= getResponseBody >>=
783 return . toString -- treat all as UTF8
776 return . toString -- treat all as UTF8
@@ -800,5 +793,5 @@ main = do
800 case writerName' of
793 case writerName' of
801 "odt" -> saveOpenDocumentAsODT datadir outputFile sourceDirRelative referenceODT writerOutput
794 "odt" -> saveOpenDocumentAsODT datadir outputFile sourceDirRelative referenceODT writerOutput
802 _ -> if outputFile == "-"
795 _ -> if outputFile == "-"
803− then putStr writerOutput
796+ then UTF8.putStr writerOutput
804− else writeFile outputFile writerOutput
797+ else UTF8.writeFile outputFile writerOutput