git.iko.soy/typeable/pandoc
on master help sign in
Revert "More intelligent handling of text encodings."

This reverts commit 7272735b3d413a644fd9ab01eeae8ae9cd5a925b.

commit12045d84b6f20c9d959f61d376bd89e722f7f50c authorJohn MacFarlane <fiddlosopher@gmail.com> dateSun 23 Sep 2012, 22:53 (14 years ago) parent7272735
5 files changed+20−30
src/Text/Pandoc/Parsing.hs+2−1 src/Text/Pandoc/Shared.hs+3−3 src/Text/Pandoc/UTF8.hs+4−16 src/Text/Pandoc/Writers/Docx.hs+3−2 src/pandoc.hs+8−8
src/Text/Pandoc/Parsing.hs+2−1
@@ -146,6 +146,7 @@ where
146146import Text.Pandoc.Definition
147147import Text.Pandoc.Options
148148import Text.Pandoc.Builder (Blocks)
149+import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
149150import Text.Parsec
150151import Text.Parsec.Pos (newPos)
151152import Data.Char ( toLower, toUpper, ord, isAscii, isAlphaNum, isDigit, isPunctuation )
@@ -707,7 +708,7 @@ readWith parser state input =
707708testStringWith :: (Show a) => Parser [Char] ParserState a
708709 -> String
709710 -> IO ()
710−testStringWith parser str = putStrLn $ show $
711+testStringWith parser str = UTF8.putStrLn $ show $
711712 readWith parser defaultParserState str
712713
713714-- | Parsing options.
src/Text/Pandoc/Shared.hs+3−3
@@ -90,7 +90,7 @@ import Paths_pandoc (getDataFileName)
9090import Text.Pandoc.Pretty (charWidth)
9191import System.Locale (defaultTimeLocale)
9292import Data.Time
93−import System.IO (stderr, hPutStrLn)
93+import System.IO (stderr)
9494import Text.HTML.TagSoup (renderTagsOptions, RenderOptions(..), Tag(..),
9595 renderOptions)
9696
@@ -503,14 +503,14 @@ readDataFile userDir fname = findDataFile userDir fname >>= UTF8.readFile
503503err :: Int -> String -> IO a
504504err exitCode msg = do
505505 name <- getProgName
506− hPutStrLn stderr $ name ++ ": " ++ msg
506+ UTF8.hPutStrLn stderr $ name ++ ": " ++ msg
507507 exitWith $ ExitFailure exitCode
508508 return undefined
509509
510510warn :: String -> IO ()
511511warn msg = do
512512 name <- getProgName
513− hPutStrLn stderr $ name ++ ": " ++ msg
513+ UTF8.hPutStrLn stderr $ name ++ ": " ++ msg
514514
515515--
516516-- 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
2525 Stability : alpha
2626 Portability : portable
2727
28−UTF-8 aware string IO functions that will work with GHC 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.
28+UTF-8 aware string IO functions that will work with GHC 6.10, 6.12, or 7.
3329-}
3430module Text.Pandoc.UTF8 ( readFile
3531 , writeFile
@@ -49,11 +45,10 @@ where
4945#else
5046import Codec.Binary.UTF8.String (encodeString, decodeString)
5147#endif
52−import Control.Exception (catch, throwIO)
53−import GHC.IO.Exception (IOException(..), IOErrorType(..))
48+
5449import System.IO hiding (readFile, writeFile, getContents,
5550 putStr, putStrLn, hPutStr, hPutStrLn, hGetContents)
56−import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn, catch )
51+import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn )
5752import qualified System.IO as IO
5853
5954readFile :: FilePath -> IO String
@@ -80,14 +75,7 @@ hPutStrLn :: Handle -> String -> IO ()
8075hPutStrLn h s = hSetEncoding h utf8 >> IO.hPutStrLn h s
8176
8277hGetContents :: Handle -> IO String
83−hGetContents h = do
84− hSetEncoding h utf8_bom
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
78+hGetContents h = hSetEncoding h utf8_bom >> IO.hGetContents h
9179
9280encodePath :: FilePath -> FilePath
9381decodeArg :: String -> String
src/Text/Pandoc/Writers/Docx.hs+3−2
@@ -33,7 +33,8 @@ import System.FilePath ( (</>) )
3333import qualified Data.ByteString.Lazy as B
3434import qualified Data.Map as M
3535import Data.ByteString.Lazy.UTF8 ( fromString, toString )
36−import System.IO ( stderr, hPutStrLn )
36+import Text.Pandoc.UTF8 as UTF8
37+import System.IO ( stderr )
3738import Codec.Archive.Zip
3839import Data.Time.Clock.POSIX
3940import Paths_pandoc ( getDataFileName )
@@ -662,7 +663,7 @@ inlineToOpenXML opts (Image alt (src, tit)) = do
662663 , mknode "wp:docPr" [("descr",tit),("id","1"),("name","Picture")] ()
663664 , graphic ] ]
664665 else do
665− liftIO $ hPutStrLn stderr $
666+ liftIO $ UTF8.hPutStrLn stderr $
666667 "Could not find image `" ++ src ++ "', skipping..."
667668 inlinesToOpenXML opts alt
668669
src/pandoc.hs+8−8
@@ -46,7 +46,7 @@ import System.Console.GetOpt
4646import Data.Char ( toLower )
4747import Data.List ( intercalate, isPrefixOf )
4848import System.Directory ( getAppUserDataDirectory, doesFileExist, findExecutable )
49−import System.IO ( stdout, hPutStr, hPutStrLn )
49+import System.IO ( stdout )
5050import System.IO.Error ( isDoesNotExistError )
5151import qualified Control.Exception as E
5252import Control.Exception.Extensible ( throwIO )
@@ -312,7 +312,7 @@ options =
312312 (\arg _ -> do
313313 templ <- getDefaultTemplate Nothing arg
314314 case templ of
315− Right t -> hPutStr stdout t
315+ Right t -> UTF8.hPutStr stdout t
316316 Left e -> error $ show e
317317 exitWith ExitSuccess)
318318 "FORMAT")
@@ -663,7 +663,7 @@ options =
663663 (NoArg
664664 (\_ -> do
665665 prg <- getProgName
666− hPutStrLn stdout (prg ++ " " ++ pandocVersion ++ compileInfo ++
666+ UTF8.hPutStrLn stdout (prg ++ " " ++ pandocVersion ++ compileInfo ++
667667 copyrightMessage)
668668 exitWith ExitSuccess ))
669669 "" -- "Print version"
@@ -672,7 +672,7 @@ options =
672672 (NoArg
673673 (\_ -> do
674674 prg <- getProgName
675− hPutStr stdout (usageMessage prg options)
675+ UTF8.hPutStr stdout (usageMessage prg options)
676676 exitWith ExitSuccess ))
677677 "" -- "Show help"
678678
@@ -827,8 +827,8 @@ main = do
827827 } = opts
828828
829829 when dumpArgs $
830− do hPutStrLn stdout outputFile
831− mapM_ (\arg -> hPutStrLn stdout arg) args
830+ do UTF8.hPutStrLn stdout outputFile
831+ mapM_ (\arg -> UTF8.hPutStrLn stdout arg) args
832832 exitWith ExitSuccess
833833
834834 let sources = if ignoreArgs then [] else args
@@ -1026,8 +1026,8 @@ main = do
10261026 writeBinary = B.writeFile (UTF8.encodePath outputFile)
10271027
10281028 let writerFn :: FilePath -> String -> IO ()
1029− writerFn "-" = putStr
1030− writerFn f = writeFile f
1029+ writerFn "-" = UTF8.putStr
1030+ writerFn f = UTF8.writeFile f
10311031
10321032 case getWriter writerName' of
10331033 Left e -> err 9 e