aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-09-23 22:53:34 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-09-23 22:53:34 -0700
commit12045d84b6f20c9d959f61d376bd89e722f7f50c (patch)
treeaa529ca369416e54782d8cd00b4a5c8f18a9034f /src/Text/Pandoc
parent7272735b3d413a644fd9ab01eeae8ae9cd5a925b (diff)
downloadpandoc-12045d84b6f20c9d959f61d376bd89e722f7f50c.tar.gz
Revert "More intelligent handling of text encodings."
This reverts commit 7272735b3d413a644fd9ab01eeae8ae9cd5a925b.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Parsing.hs3
-rw-r--r--src/Text/Pandoc/Shared.hs6
-rw-r--r--src/Text/Pandoc/UTF8.hs20
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs5
4 files changed, 12 insertions, 22 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index de4e3a65d..bee96be82 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -146,6 +146,7 @@ where
import Text.Pandoc.Definition
import Text.Pandoc.Options
import Text.Pandoc.Builder (Blocks)
+import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
import Text.Parsec
import Text.Parsec.Pos (newPos)
import Data.Char ( toLower, toUpper, ord, isAscii, isAlphaNum, isDigit, isPunctuation )
@@ -707,7 +708,7 @@ readWith parser state input =
testStringWith :: (Show a) => Parser [Char] ParserState a
-> String
-> IO ()
-testStringWith parser str = putStrLn $ show $
+testStringWith parser str = UTF8.putStrLn $ show $
readWith parser defaultParserState str
-- | Parsing options.
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index fa928455d..d86f9a390 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -90,7 +90,7 @@ import Paths_pandoc (getDataFileName)
import Text.Pandoc.Pretty (charWidth)
import System.Locale (defaultTimeLocale)
import Data.Time
-import System.IO (stderr, hPutStrLn)
+import System.IO (stderr)
import Text.HTML.TagSoup (renderTagsOptions, RenderOptions(..), Tag(..),
renderOptions)
@@ -503,14 +503,14 @@ readDataFile userDir fname = findDataFile userDir fname >>= UTF8.readFile
err :: Int -> String -> IO a
err exitCode msg = do
name <- getProgName
- hPutStrLn stderr $ name ++ ": " ++ msg
+ UTF8.hPutStrLn stderr $ name ++ ": " ++ msg
exitWith $ ExitFailure exitCode
return undefined
warn :: String -> IO ()
warn msg = do
name <- getProgName
- hPutStrLn stderr $ name ++ ": " ++ msg
+ UTF8.hPutStrLn stderr $ name ++ ": " ++ msg
--
-- Safe read
diff --git a/src/Text/Pandoc/UTF8.hs b/src/Text/Pandoc/UTF8.hs
index 45664892a..aa3a9da04 100644
--- a/src/Text/Pandoc/UTF8.hs
+++ b/src/Text/Pandoc/UTF8.hs
@@ -25,11 +25,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Stability : alpha
Portability : portable
-UTF-8 aware string IO functions that will work with GHC 6.12 or 7.
-The reading functions first attempt to read UTF-8; if an encoding
-error is encountered, the local encoding is used instead. This
-should work well in practice because text in other encodings
-is usually not valid UTF-8.
+UTF-8 aware string IO functions that will work with GHC 6.10, 6.12, or 7.
-}
module Text.Pandoc.UTF8 ( readFile
, writeFile
@@ -49,11 +45,10 @@ where
#else
import Codec.Binary.UTF8.String (encodeString, decodeString)
#endif
-import Control.Exception (catch, throwIO)
-import GHC.IO.Exception (IOException(..), IOErrorType(..))
+
import System.IO hiding (readFile, writeFile, getContents,
putStr, putStrLn, hPutStr, hPutStrLn, hGetContents)
-import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn, catch )
+import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn )
import qualified System.IO as IO
readFile :: FilePath -> IO String
@@ -80,14 +75,7 @@ hPutStrLn :: Handle -> String -> IO ()
hPutStrLn h s = hSetEncoding h utf8 >> IO.hPutStrLn h s
hGetContents :: Handle -> IO String
-hGetContents h = do
- hSetEncoding h utf8_bom
- catch (IO.hGetContents h) $ \e ->
- case ioe_type e of
- InvalidArgument -> do
- hSetEncoding h localeEncoding
- IO.hGetContents h
- _ -> throwIO e
+hGetContents h = hSetEncoding h utf8_bom >> IO.hGetContents h
encodePath :: FilePath -> FilePath
decodeArg :: String -> String
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index 211f8946b..84bf95dfb 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -33,7 +33,8 @@ import System.FilePath ( (</>) )
import qualified Data.ByteString.Lazy as B
import qualified Data.Map as M
import Data.ByteString.Lazy.UTF8 ( fromString, toString )
-import System.IO ( stderr, hPutStrLn )
+import Text.Pandoc.UTF8 as UTF8
+import System.IO ( stderr )
import Codec.Archive.Zip
import Data.Time.Clock.POSIX
import Paths_pandoc ( getDataFileName )
@@ -662,7 +663,7 @@ inlineToOpenXML opts (Image alt (src, tit)) = do
, mknode "wp:docPr" [("descr",tit),("id","1"),("name","Picture")] ()
, graphic ] ]
else do
- liftIO $ hPutStrLn stderr $
+ liftIO $ UTF8.hPutStrLn stderr $
"Could not find image `" ++ src ++ "', skipping..."
inlinesToOpenXML opts alt