aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/App.hs12
-rw-r--r--src/Text/Pandoc/App/CommandLineOptions.hs6
-rw-r--r--src/Text/Pandoc/App/Opt.hs13
-rw-r--r--src/Text/Pandoc/App/OutputSettings.hs5
-rw-r--r--test/command/lua-pandoc-state.md2
5 files changed, 22 insertions, 16 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
index ecbdeecd8..4dcd76a24 100644
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -75,7 +75,7 @@ convertWithOpts opts = do
when (optDumpArgs opts) $
do UTF8.hPutStrLn stdout outputFile
- mapM_ (UTF8.hPutStrLn stdout) (optInputFiles opts)
+ mapM_ (UTF8.hPutStrLn stdout) (fromMaybe ["-"] $ optInputFiles opts)
exitSuccess
let isPandocCiteproc (JSONFilter f) = takeBaseName f == "pandoc-citeproc"
@@ -88,9 +88,9 @@ convertWithOpts opts = do
let filters' = filters ++ [ JSONFilter "pandoc-citeproc" | needsCiteproc ]
let sources = case optInputFiles opts of
- [] -> ["-"]
- xs | optIgnoreArgs opts -> ["-"]
- | otherwise -> xs
+ Nothing -> ["-"]
+ Just xs | optIgnoreArgs opts -> ["-"]
+ | otherwise -> xs
datadir <- case optDataDir opts of
Nothing -> do
@@ -132,7 +132,7 @@ convertWithOpts opts = do
runIO' $ do
setUserDataDir datadir
- setInputFiles (optInputFiles opts)
+ setInputFiles (fromMaybe ["-"] (optInputFiles opts))
setOutputFile (optOutputFile opts)
-- assign reader and writer based on options and filenames
@@ -151,7 +151,7 @@ convertWithOpts opts = do
when (pdfOutput && readerName == "latex") $
case (optInputFiles opts) of
- (inputFile:_) -> report $ UnusualConversion $ T.pack $
+ Just (inputFile:_) -> report $ UnusualConversion $ T.pack $
"to convert a .tex file to PDF, you get better results by using pdflatex "
<> "(or lualatex or xelatex) directly, try `pdflatex " <> inputFile
<> "` instead of `pandoc " <> inputFile <> " -o " <> outputFile <> "`."
diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs
index 56b1f780a..1776107ff 100644
--- a/src/Text/Pandoc/App/CommandLineOptions.hs
+++ b/src/Text/Pandoc/App/CommandLineOptions.hs
@@ -85,7 +85,11 @@ parseOptions options' defaults = do
-- thread option data structure through all supplied option actions
opts <- foldl (>>=) (return defaults) actions
- return (opts{ optInputFiles = map normalizePath $ optInputFiles opts ++ args })
+ let mbArgs = case args of
+ [] -> Nothing
+ xs -> Just xs
+ return $ opts{ optInputFiles =
+ map normalizePath <$> (optInputFiles opts <> mbArgs) }
latexEngines :: [String]
latexEngines = ["pdflatex", "lualatex", "xelatex", "latexmk", "tectonic"]
diff --git a/src/Text/Pandoc/App/Opt.hs b/src/Text/Pandoc/App/Opt.hs
index 402d09bb7..ed167fff2 100644
--- a/src/Text/Pandoc/App/Opt.hs
+++ b/src/Text/Pandoc/App/Opt.hs
@@ -85,7 +85,7 @@ data Opt = Opt
, optMetadata :: Meta -- ^ Metadata fields to set
, optMetadataFiles :: [FilePath] -- ^ Name of YAML metadata files
, optOutputFile :: Maybe FilePath -- ^ Name of output file
- , optInputFiles :: [FilePath] -- ^ Names of input files
+ , optInputFiles :: Maybe [FilePath] -- ^ Names of input files
, optNumberSections :: Bool -- ^ Number sections in LaTeX
, optNumberOffset :: [Int] -- ^ Starting number for sections
, optSectionDivs :: Bool -- ^ Put sections in div tags in HTML
@@ -200,16 +200,17 @@ doOpt (k',v) = do
"output-file" ->
parseYAML v >>= \x -> return (\o -> o{ optOutputFile = unpack <$> x })
"input-files" ->
- parseYAML v >>= \x -> return (\o -> o{ optInputFiles = optInputFiles o <>
- map unpack x })
+ parseYAML v >>= \x -> return (\o -> o{ optInputFiles =
+ optInputFiles o <>
+ Just (map unpack x) })
"input-file" -> -- allow either a list or a single value
(parseYAML v >>= \x -> return (\o -> o{ optInputFiles =
optInputFiles o <>
- map unpack x }))
+ Just (map unpack x) }))
<|>
(parseYAML v >>= \x -> return (\o -> o{ optInputFiles =
optInputFiles o <>
- [unpack x] }))
+ Just [unpack x] }))
"number-sections" ->
parseYAML v >>= \x -> return (\o -> o{ optNumberSections = x })
"number-offset" ->
@@ -390,7 +391,7 @@ defaultOpts = Opt
, optMetadata = mempty
, optMetadataFiles = []
, optOutputFile = Nothing
- , optInputFiles = []
+ , optInputFiles = Nothing
, optNumberSections = False
, optNumberOffset = [0,0,0,0,0,0]
, optSectionDivs = False
diff --git a/src/Text/Pandoc/App/OutputSettings.hs b/src/Text/Pandoc/App/OutputSettings.hs
index 4f33bd336..944f1b63b 100644
--- a/src/Text/Pandoc/App/OutputSettings.hs
+++ b/src/Text/Pandoc/App/OutputSettings.hs
@@ -63,7 +63,7 @@ optToOutputSettings opts = do
when (optDumpArgs opts) . liftIO $ do
UTF8.hPutStrLn stdout outputFile
- mapM_ (UTF8.hPutStrLn stdout) (optInputFiles opts)
+ mapM_ (UTF8.hPutStrLn stdout) (fromMaybe [] $ optInputFiles opts)
exitSuccess
epubMetadata <- case optEpubMetadata opts of
@@ -140,7 +140,8 @@ optToOutputSettings opts = do
variables <-
return (optVariables opts)
>>=
- setListVariableM "sourcefile" (T.pack <$> optInputFiles opts)
+ setListVariableM "sourcefile"
+ (maybe ["-"] (fmap T.pack) (optInputFiles opts))
>>=
setVariableM "outputfile" outputFile
>>=
diff --git a/test/command/lua-pandoc-state.md b/test/command/lua-pandoc-state.md
index 2aece619b..e56d75af5 100644
--- a/test/command/lua-pandoc-state.md
+++ b/test/command/lua-pandoc-state.md
@@ -2,7 +2,7 @@
% pandoc --lua-filter=command/lua-pandoc-state.lua --data-dir=foo
Hello
^D
- # input files: 0
+ # input files: 1
output file: nil
# request header: 0
resource path: .