git.iko.soy/typeable/pandoc
on master help sign in
Revert "More intelligent handling of text encodings."
12045d8John 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/Text/Pandoc/Shared.hs+3−3
@@ -90,7 +90,7 @@ import Paths_pandoc (getDataFileName)
90import Text.Pandoc.Pretty (charWidth)
90import Text.Pandoc.Pretty (charWidth)
91import System.Locale (defaultTimeLocale)
91import System.Locale (defaultTimeLocale)
92import Data.Time
92import Data.Time
93−import System.IO (stderr, hPutStrLn)
93+import System.IO (stderr)
94import Text.HTML.TagSoup (renderTagsOptions, RenderOptions(..), Tag(..),
94import Text.HTML.TagSoup (renderTagsOptions, RenderOptions(..), Tag(..),
95 renderOptions)
95 renderOptions)
96
96
@@ -503,14 +503,14 @@ readDataFile userDir fname = findDataFile userDir fname >>= UTF8.readFile
503err :: Int -> String -> IO a
503err :: Int -> String -> IO a
504err exitCode msg = do
504err exitCode msg = do
505 name <- getProgName
505 name <- getProgName
506− hPutStrLn stderr $ name ++ ": " ++ msg
506+ UTF8.hPutStrLn stderr $ name ++ ": " ++ msg
507 exitWith $ ExitFailure exitCode
507 exitWith $ ExitFailure exitCode
508 return undefined
508 return undefined
509
509
510warn :: String -> IO ()
510warn :: String -> IO ()
511warn msg = do
511warn msg = do
512 name <- getProgName
512 name <- getProgName
513− hPutStrLn stderr $ name ++ ": " ++ msg
513+ UTF8.hPutStrLn stderr $ name ++ ": " ++ msg
514
514
515--
515--
516-- Safe read
516-- Safe read
src/Text/Pandoc/UTF8.hs+4−16
@@ -25,11 +25,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 Stability : alpha
25 Stability : alpha
26 Portability : portable
26 Portability : portable
27
27
28−UTF-8 aware string IO functions that will work with GHC 6.12 or 7.
28+UTF-8 aware string IO functions that will work with GHC 6.10, 6.12, or 7.
29−The reading functions first attempt to read UTF-8; if an encoding
30−error is encountered, the local encoding is used instead. This
31−should work well in practice because text in other encodings
32−is usually not valid UTF-8.
33-}
29-}
34module Text.Pandoc.UTF8 ( readFile
30module Text.Pandoc.UTF8 ( readFile
35 , writeFile
31 , writeFile
@@ -49,11 +45,10 @@ where
49#else
45#else
50import Codec.Binary.UTF8.String (encodeString, decodeString)
46import Codec.Binary.UTF8.String (encodeString, decodeString)
51#endif
47#endif
52−import Control.Exception (catch, throwIO)
48+
53−import GHC.IO.Exception (IOException(..), IOErrorType(..))
54import System.IO hiding (readFile, writeFile, getContents,
49import System.IO hiding (readFile, writeFile, getContents,
55 putStr, putStrLn, hPutStr, hPutStrLn, hGetContents)
50 putStr, putStrLn, hPutStr, hPutStrLn, hGetContents)
56−import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn, catch )
51+import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn )
57import qualified System.IO as IO
52import qualified System.IO as IO
58
53
59readFile :: FilePath -> IO String
54readFile :: FilePath -> IO String
@@ -80,14 +75,7 @@ hPutStrLn :: Handle -> String -> IO ()
80hPutStrLn h s = hSetEncoding h utf8 >> IO.hPutStrLn h s
75hPutStrLn h s = hSetEncoding h utf8 >> IO.hPutStrLn h s
81
76
82hGetContents :: Handle -> IO String
77hGetContents :: Handle -> IO String
83−hGetContents h = do
84− hSetEncoding h utf8_bom
78+hGetContents h = hSetEncoding h utf8_bom >> IO.hGetContents h
85− catch (IO.hGetContents h) $ \e ->
86− case ioe_type e of
87− InvalidArgument -> do
88− hSetEncoding h localeEncoding
89− IO.hGetContents h
90− _ -> throwIO e
91
79
92encodePath :: FilePath -> FilePath
80encodePath :: FilePath -> FilePath
93decodeArg :: String -> String
81decodeArg :: String -> String
src/Text/Pandoc/Writers/Docx.hs+3−2
@@ -33,7 +33,8 @@ import System.FilePath ( (</>) )
33import qualified Data.ByteString.Lazy as B
33import qualified Data.ByteString.Lazy as B
34import qualified Data.Map as M
34import qualified Data.Map as M
35import Data.ByteString.Lazy.UTF8 ( fromString, toString )
35import Data.ByteString.Lazy.UTF8 ( fromString, toString )
36+import Text.Pandoc.UTF8 as UTF8
36−import System.IO ( stderr, hPutStrLn )
37+import System.IO ( stderr )
37import Codec.Archive.Zip
38import Codec.Archive.Zip
38import Data.Time.Clock.POSIX
39import Data.Time.Clock.POSIX
39import Paths_pandoc ( getDataFileName )
40import Paths_pandoc ( getDataFileName )
@@ -662,7 +663,7 @@ inlineToOpenXML opts (Image alt (src, tit)) = do
662 , mknode "wp:docPr" [("descr",tit),("id","1"),("name","Picture")] ()
663 , mknode "wp:docPr" [("descr",tit),("id","1"),("name","Picture")] ()
663 , graphic ] ]
664 , graphic ] ]
664 else do
665 else do
665− liftIO $ hPutStrLn stderr $
666+ liftIO $ UTF8.hPutStrLn stderr $
666 "Could not find image `" ++ src ++ "', skipping..."
667 "Could not find image `" ++ src ++ "', skipping..."
667 inlinesToOpenXML opts alt
668 inlinesToOpenXML opts alt
668
669
src/pandoc.hs+8−8
@@ -46,7 +46,7 @@ import System.Console.GetOpt
46import Data.Char ( toLower )
46import Data.Char ( toLower )
47import Data.List ( intercalate, isPrefixOf )
47import Data.List ( intercalate, isPrefixOf )
48import System.Directory ( getAppUserDataDirectory, doesFileExist, findExecutable )
48import System.Directory ( getAppUserDataDirectory, doesFileExist, findExecutable )
49−import System.IO ( stdout, hPutStr, hPutStrLn )
49+import System.IO ( stdout )
50import System.IO.Error ( isDoesNotExistError )
50import System.IO.Error ( isDoesNotExistError )
51import qualified Control.Exception as E
51import qualified Control.Exception as E
52import Control.Exception.Extensible ( throwIO )
52import Control.Exception.Extensible ( throwIO )
@@ -312,7 +312,7 @@ options =
312 (\arg _ -> do
312 (\arg _ -> do
313 templ <- getDefaultTemplate Nothing arg
313 templ <- getDefaultTemplate Nothing arg
314 case templ of
314 case templ of
315− Right t -> hPutStr stdout t
315+ Right t -> UTF8.hPutStr stdout t
316 Left e -> error $ show e
316 Left e -> error $ show e
317 exitWith ExitSuccess)
317 exitWith ExitSuccess)
318 "FORMAT")
318 "FORMAT")
@@ -663,7 +663,7 @@ options =
663 (NoArg
663 (NoArg
664 (\_ -> do
664 (\_ -> do
665 prg <- getProgName
665 prg <- getProgName
666− hPutStrLn stdout (prg ++ " " ++ pandocVersion ++ compileInfo ++
666+ UTF8.hPutStrLn stdout (prg ++ " " ++ pandocVersion ++ compileInfo ++
667 copyrightMessage)
667 copyrightMessage)
668 exitWith ExitSuccess ))
668 exitWith ExitSuccess ))
669 "" -- "Print version"
669 "" -- "Print version"
@@ -672,7 +672,7 @@ options =
672 (NoArg
672 (NoArg
673 (\_ -> do
673 (\_ -> do
674 prg <- getProgName
674 prg <- getProgName
675− hPutStr stdout (usageMessage prg options)
675+ UTF8.hPutStr stdout (usageMessage prg options)
676 exitWith ExitSuccess ))
676 exitWith ExitSuccess ))
677 "" -- "Show help"
677 "" -- "Show help"
678
678
@@ -827,8 +827,8 @@ main = do
827 } = opts
827 } = opts
828
828
829 when dumpArgs $
829 when dumpArgs $
830− do hPutStrLn stdout outputFile
830+ do UTF8.hPutStrLn stdout outputFile
831− mapM_ (\arg -> hPutStrLn stdout arg) args
831+ mapM_ (\arg -> UTF8.hPutStrLn stdout arg) args
832 exitWith ExitSuccess
832 exitWith ExitSuccess
833
833
834 let sources = if ignoreArgs then [] else args
834 let sources = if ignoreArgs then [] else args
@@ -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 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