From 5a02a81b43f1081aa6fb7025428f416cfd4abaa4 Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Wed, 30 Nov 2016 13:55:52 -0500 Subject: Have to do some work to get the mediabag out. --- pandoc.cabal | 3 ++- pandoc.hs | 33 ++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/pandoc.cabal b/pandoc.cabal index 77ef869a5..ef253f79a 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -436,7 +436,8 @@ Executable pandoc aeson >= 0.7.0.5 && < 1.2, yaml >= 0.8.8.2 && < 0.9, containers >= 0.1 && < 0.6, - HTTP >= 4000.0.5 && < 4000.4 + HTTP >= 4000.0.5 && < 4000.4, + mtl >= 2.2 && < 2.3 if flag(network-uri) Build-Depends: network-uri >= 2.6 && < 2.7, network >= 2.6 else diff --git a/pandoc.hs b/pandoc.hs index 258b0c735..646ec3a0e 100644 --- a/pandoc.hs +++ b/pandoc.hs @@ -77,7 +77,9 @@ import Text.Printf (printf) import System.Posix.Terminal (queryTerminal) import System.Posix.IO (stdOutput) #endif -import Text.Pandoc.Class (runIOorExplode, PandocIO) +import Control.Monad.Trans +import Text.Pandoc.Class (runIOorExplode, PandocMonad, PandocIO) +import qualified Text.Pandoc.Class as P type Transform = Pandoc -> Pandoc @@ -1285,11 +1287,9 @@ convertWithOpts opts args = do else e Right w -> return w - reader <- if "t2t" == readerName' - then (mkStringReader . - readTxt2Tags) <$> - getT2TMeta sources outputFile - else case getReader readerName' of + -- TODO: we have to get the input and the output into the state for + -- the sake of the text2tags reader. + reader <- case getReader readerName' of Right r -> return r Left e -> err 7 e' where e' = case readerName' of @@ -1374,19 +1374,26 @@ convertWithOpts opts args = do err 5 $ "Cannot write " ++ format ++ " output to stdout.\n" ++ "Specify an output file using the -o option." - let readSources [] = mapM readSource ["-"] - readSources srcs = mapM readSource srcs - readSource "-" = UTF8.getContents + let readSource :: MonadIO m => FilePath -> m String + readSource "-" = liftIO UTF8.getContents readSource src = case parseURI src of Just u | uriScheme u `elem` ["http:","https:"] -> readURI src | uriScheme u == "file:" -> - UTF8.readFile (uriPath u) - _ -> UTF8.readFile src + liftIO $ UTF8.readFile (uriPath u) + _ -> liftIO $ UTF8.readFile src + + + + readSources :: MonadIO m => [FilePath] -> m [String] + readSources [] = mapM readSource ["-"] + readSources srcs = mapM readSource srcs + + readURI :: MonadIO m => FilePath -> m String readURI src = do - res <- openURL src + res <- liftIO $ openURL src case res of - Left e -> throwIO e + Left e -> liftIO $ throwIO e Right (bs,_) -> return $ UTF8.toString bs let readFiles [] = error "Cannot read archive from stdin" -- cgit v1.2.3