aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2019-09-22 14:00:16 -0700
committerJohn MacFarlane <[email protected]>2019-09-22 14:00:16 -0700
commit4b54454c8f49678d48e7fb33fd7f5471672ad3c7 (patch)
tree7e3cb227454ae27b5743593c757e168de0ac2b65
parentc330b2f292899697ccc26b854f33ac9c22a8c716 (diff)
Class: remove stStdin and readStdinStrict.
Instead, treat "-" as an alias for stdin in readFileLazy/Strict.
-rw-r--r--src/Text/Pandoc/App.hs6
-rw-r--r--src/Text/Pandoc/Class.hs23
-rw-r--r--src/Text/Pandoc/Error.hs4
3 files changed, 11 insertions, 22 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
index 1792a39bb..8f6eac40e 100644
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -275,7 +275,7 @@ convertWithOpts opts = do
r readerOpts . convertTabs
ByteStringReader r ->
mconcat <$> mapM
- (readFile' >=> r readerOpts) sources'
+ (readFileLazy >=> r readerOpts) sources'
when (readerName == "markdown_github" ||
@@ -376,10 +376,6 @@ readSources srcs = T.intercalate (T.pack "\n") <$> mapM readSource srcs
readURI :: PandocMonad m => FilePath -> m Text
readURI src = UTF8.toText . fst <$> openURL src
-readFile' :: PandocMonad m => FilePath -> m BL.ByteString
-readFile' "-" = BL.fromStrict <$> readStdinStrict
-readFile' f = readFileLazy f
-
writeFnBinary :: MonadIO m => FilePath -> BL.ByteString -> m ()
writeFnBinary "-" = liftIO . BL.putStr
writeFnBinary f = liftIO . BL.writeFile (UTF8.encodePath f)
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs
index eabaf14fa..7d4db600c 100644
--- a/src/Text/Pandoc/Class.hs
+++ b/src/Text/Pandoc/Class.hs
@@ -171,14 +171,11 @@ class (Functor m, Applicative m, Monad m, MonadError PandocError m)
-- an error on failure.
openURL :: String -> m (B.ByteString, Maybe MimeType)
-- | Read the lazy ByteString contents from a file path,
- -- raising an error on failure.
+ -- raising an error on failure. The path "-" is treated as stdin.
readFileLazy :: FilePath -> m BL.ByteString
-- | Read the strict ByteString contents from a file path,
- -- raising an error on failure.
+ -- raising an error on failure. The path "-" is treated as stdin.
readFileStrict :: FilePath -> m B.ByteString
- -- | Read from stdin as a strict ByteString, raising an
- -- error on failure.
- readStdinStrict :: m B.ByteString
-- | Return a list of paths that match a glob, relative to
-- the working directory. See 'System.FilePath.Glob' for
-- the glob syntax.
@@ -242,9 +239,7 @@ report msg = do
-- not UTF-8 encoded. If file path is "-", stdin is read instead.
readTextFile :: PandocMonad m => FilePath -> m Text
readTextFile fp = do
- bs <- if fp == "-"
- then readStdinStrict
- else readFileStrict fp
+ bs <- readFileStrict fp
case decodeUtf8' . filterCRs . dropBOM $ bs of
Right t -> return t
Left (TSE.DecodeError _ (Just w)) -> throwError $
@@ -532,9 +527,10 @@ instance PandocMonad PandocIO where
Right r -> return r
Left e -> throwError $ PandocHttpError u e
- readFileLazy s = liftIOError BL.readFile s
- readFileStrict s = liftIOError B.readFile s
- readStdinStrict = liftIOError (\_ -> B.getContents) "stdin"
+ readFileLazy "-" = liftIOError (\_ -> BL.getContents) "stdin"
+ readFileLazy s = liftIOError BL.readFile s
+ readFileStrict "-" = liftIOError (\_ -> B.getContents) "stdin"
+ readFileStrict s = liftIOError B.readFile s
glob = liftIOError IO.glob
fileExists = liftIOError Directory.doesFileExist
#ifdef EMBED_DATA_FILES
@@ -914,7 +910,6 @@ data PureState = PureState { stStdGen :: StdGen
, stReferencePptx :: Archive
, stReferenceODT :: Archive
, stFiles :: FileTree
- , stStdin :: B.ByteString
, stUserDataFiles :: FileTree
, stCabalDataFiles :: FileTree
}
@@ -930,7 +925,6 @@ instance Default PureState where
, stReferencePptx = emptyArchive
, stReferenceODT = emptyArchive
, stFiles = mempty
- , stStdin = mempty
, stUserDataFiles = mempty
, stCabalDataFiles = mempty
}
@@ -1032,7 +1026,6 @@ instance PandocMonad PandocPure where
case infoFileContents <$> getFileInfo fp fps of
Just bs -> return bs
Nothing -> throwError $ PandocResourceNotFound fp
- readStdinStrict = getsPureState stStdin
glob s = do
FileTree ftmap <- getsPureState stFiles
@@ -1073,7 +1066,6 @@ instance (MonadTrans t, PandocMonad m, Functor (t m),
openURL = lift . openURL
readFileLazy = lift . readFileLazy
readFileStrict = lift . readFileStrict
- readStdinStrict = lift readStdinStrict
glob = lift . glob
fileExists = lift . fileExists
getDataFileName = lift . getDataFileName
@@ -1091,7 +1083,6 @@ instance {-# OVERLAPS #-} PandocMonad m => PandocMonad (ParsecT s st m) where
openURL = lift . openURL
readFileLazy = lift . readFileLazy
readFileStrict = lift . readFileStrict
- readStdinStrict = lift readStdinStrict
glob = lift . glob
fileExists = lift . fileExists
getDataFileName = lift . getDataFileName
diff --git a/src/Text/Pandoc/Error.hs b/src/Text/Pandoc/Error.hs
index ae66162b3..e4ddce42a 100644
--- a/src/Text/Pandoc/Error.hs
+++ b/src/Text/Pandoc/Error.hs
@@ -63,7 +63,9 @@ handleError :: Either PandocError a -> IO a
handleError (Right r) = return r
handleError (Left e) =
case e of
- PandocIOError _ err' -> ioError err'
+ PandocIOError fp err' -> do
+ UTF8.hPutStrLn stderr $ "IO Error (" ++ show fp ++ ")"
+ ioError err'
PandocHttpError u err' -> err 61 $
"Could not fetch " ++ u ++ "\n" ++ show err'
PandocShouldNeverHappenError s -> err 62 $