git.iko.soy/typeable/pandoc
on master help sign in
More refactoring of pandoc.hs for clarity.
commit1bdf23c6971e0c2b0fd2e7763dc3fa74f908d4d1 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 10 Dec 2016, 11:12 (10 years ago) parent8beba65
1 file changed+25−22
pandoc.hs+25−22
pandoc.hs+25−22
@@ -1224,7 +1224,10 @@ convertWithOpts opts args = do
12241224 let filters' = if needsCiteproc then "pandoc-citeproc" : filters
12251225 else filters
12261226
1227− let sources = if ignoreArgs then [] else args
1227+ let sources = case args of
1228+ [] -> ["-"]
1229+ xs | ignoreArgs -> ["-"]
1230+ | otherwise -> xs
12281231
12291232 datadir <- case mbDataDir of
12301233 Nothing -> E.catch
@@ -1404,7 +1407,12 @@ convertWithOpts opts args = do
14041407 err 5 $ "Cannot write " ++ format ++ " output to stdout.\n" ++
14051408 "Specify an output file using the -o option."
14061409
1407− let readSource :: MonadIO m => FilePath -> m String
1410+
1411+ let convertTabs = tabFilter (if preserveTabs || readerName' == "t2t"
1412+ then 0
1413+ else tabStop)
1414+
1415+ readSource :: MonadIO m => FilePath -> m String
14081416 readSource "-" = liftIO UTF8.getContents
14091417 readSource src = case parseURI src of
14101418 Just u | uriScheme u `elem` ["http:","https:"] ->
@@ -1413,12 +1421,6 @@ convertWithOpts opts args = do
14131421 liftIO $ UTF8.readFile (uriPath u)
14141422 _ -> liftIO $ UTF8.readFile src
14151423
1416−
1417−
1418− readSources :: MonadIO m => [FilePath] -> m [String]
1419− readSources [] = mapM readSource ["-"]
1420− readSources srcs = mapM readSource srcs
1421−
14221424 readURI :: MonadIO m => FilePath -> m String
14231425 readURI src = do
14241426 res <- liftIO $ openURL src
@@ -1426,13 +1428,16 @@ convertWithOpts opts args = do
14261428 Left e -> liftIO $ throwIO e
14271429 Right (bs,_) -> return $ UTF8.toString bs
14281430
1429− let readFiles [] = error "Cannot read archive from stdin"
1430− readFiles [x] = B.readFile x
1431− readFiles (x:xs) = mapM_ (warn . ("Ignoring: " ++)) xs >> B.readFile x
1431+ readSources :: MonadIO m => [FilePath] -> m String
1432+ readSources srcs = convertTabs . intercalate "\n" <$>
1433+ mapM readSource srcs
14321434
1433− let convertTabs = tabFilter (if preserveTabs || readerName' == "t2t"
1434− then 0
1435− else tabStop)
1435+ let readFiles :: MonadIO m => [FilePath] -> m B.ByteString
1436+ readFiles [] = error "Cannot read archive from stdin"
1437+ readFiles [x] = liftIO $ B.readFile x
1438+ readFiles (x:xs) = do
1439+ mapM_ (warn . ("Ignoring: " ++)) xs
1440+ liftIO $ B.readFile x
14361441
14371442 let runIO' f = do
14381443 (res, warnings) <- runIOorExplode $ do
@@ -1447,14 +1452,12 @@ convertWithOpts opts args = do
14471452 return res
14481453
14491454 let sourceToDoc :: [FilePath] -> IO (Pandoc, MediaBag)
1450− sourceToDoc sources' =
1451− case reader of
1452− StringReader r-> do
1453− doc <- convertTabs . intercalate "\n" <$> readSources sources'
1454− runIO' $ withMediaBag $ r readerOpts doc
1455− ByteStringReader r -> readFiles sources' >>=
1456− (\bs -> runIO' $ withMediaBag
1457− $ r readerOpts bs)
1455+ sourceToDoc sources' = runIO' $
1456+ case reader of
1457+ StringReader r -> readSources sources' >>=
1458+ withMediaBag . r readerOpts
1459+ ByteStringReader r -> readFiles sources' >>=
1460+ withMediaBag . r readerOpts
14581461
14591462 -- We parse first if (1) fileScope is set, (2), it's a binary
14601463 -- reader, or (3) we're reading JSON. This is easier to do of an AND