git.iko.soy/typeable/pandoc
on master help sign in
Change optInputFiles to a `Maybe [FilePath]`.
81fae63John MacFarlane
src/Text/Pandoc/App.hs+6−6
@@ -75,7 +75,7 @@ convertWithOpts opts = do
75
75
76 when (optDumpArgs opts) $
76 when (optDumpArgs opts) $
77 do UTF8.hPutStrLn stdout outputFile
77 do UTF8.hPutStrLn stdout outputFile
78− mapM_ (UTF8.hPutStrLn stdout) (optInputFiles opts)
78+ mapM_ (UTF8.hPutStrLn stdout) (fromMaybe ["-"] $ optInputFiles opts)
79 exitSuccess
79 exitSuccess
80
80
81 let isPandocCiteproc (JSONFilter f) = takeBaseName f == "pandoc-citeproc"
81 let isPandocCiteproc (JSONFilter f) = takeBaseName f == "pandoc-citeproc"
@@ -88,9 +88,9 @@ convertWithOpts opts = do
88 let filters' = filters ++ [ JSONFilter "pandoc-citeproc" | needsCiteproc ]
88 let filters' = filters ++ [ JSONFilter "pandoc-citeproc" | needsCiteproc ]
89
89
90 let sources = case optInputFiles opts of
90 let sources = case optInputFiles opts of
91− [] -> ["-"]
91+ Nothing -> ["-"]
92− xs | optIgnoreArgs opts -> ["-"]
92+ Just xs | optIgnoreArgs opts -> ["-"]
93− | otherwise -> xs
93+ | otherwise -> xs
94
94
95 datadir <- case optDataDir opts of
95 datadir <- case optDataDir opts of
96 Nothing -> do
96 Nothing -> do
@@ -132,7 +132,7 @@ convertWithOpts opts = do
132
132
133 runIO' $ do
133 runIO' $ do
134 setUserDataDir datadir
134 setUserDataDir datadir
135− setInputFiles (optInputFiles opts)
135+ setInputFiles (fromMaybe ["-"] (optInputFiles opts))
136 setOutputFile (optOutputFile opts)
136 setOutputFile (optOutputFile opts)
137
137
138 -- assign reader and writer based on options and filenames
138 -- assign reader and writer based on options and filenames
@@ -151,7 +151,7 @@ convertWithOpts opts = do
151
151
152 when (pdfOutput && readerName == "latex") $
152 when (pdfOutput && readerName == "latex") $
153 case (optInputFiles opts) of
153 case (optInputFiles opts) of
154− (inputFile:_) -> report $ UnusualConversion $ T.pack $
154+ Just (inputFile:_) -> report $ UnusualConversion $ T.pack $
155 "to convert a .tex file to PDF, you get better results by using pdflatex "
155 "to convert a .tex file to PDF, you get better results by using pdflatex "
156 <> "(or lualatex or xelatex) directly, try `pdflatex " <> inputFile
156 <> "(or lualatex or xelatex) directly, try `pdflatex " <> inputFile
157 <> "` instead of `pandoc " <> inputFile <> " -o " <> outputFile <> "`."
157 <> "` instead of `pandoc " <> inputFile <> " -o " <> outputFile <> "`."
src/Text/Pandoc/App/CommandLineOptions.hs+5−1
@@ -85,7 +85,11 @@ parseOptions options' defaults = do
85
85
86 -- thread option data structure through all supplied option actions
86 -- thread option data structure through all supplied option actions
87 opts <- foldl (>>=) (return defaults) actions
87 opts <- foldl (>>=) (return defaults) actions
88+ let mbArgs = case args of
89+ [] -> Nothing
90+ xs -> Just xs
91+ return $ opts{ optInputFiles =
88− return (opts{ optInputFiles = map normalizePath $ optInputFiles opts ++ args })
92+ map normalizePath <$> (optInputFiles opts <> mbArgs) }
89
93
90latexEngines :: [String]
94latexEngines :: [String]
91latexEngines = ["pdflatex", "lualatex", "xelatex", "latexmk", "tectonic"]
95latexEngines = ["pdflatex", "lualatex", "xelatex", "latexmk", "tectonic"]
src/Text/Pandoc/App/Opt.hs+7−6
@@ -85,7 +85,7 @@ data Opt = Opt
85 , optMetadata :: Meta -- ^ Metadata fields to set
85 , optMetadata :: Meta -- ^ Metadata fields to set
86 , optMetadataFiles :: [FilePath] -- ^ Name of YAML metadata files
86 , optMetadataFiles :: [FilePath] -- ^ Name of YAML metadata files
87 , optOutputFile :: Maybe FilePath -- ^ Name of output file
87 , optOutputFile :: Maybe FilePath -- ^ Name of output file
88− , optInputFiles :: [FilePath] -- ^ Names of input files
88+ , optInputFiles :: Maybe [FilePath] -- ^ Names of input files
89 , optNumberSections :: Bool -- ^ Number sections in LaTeX
89 , optNumberSections :: Bool -- ^ Number sections in LaTeX
90 , optNumberOffset :: [Int] -- ^ Starting number for sections
90 , optNumberOffset :: [Int] -- ^ Starting number for sections
91 , optSectionDivs :: Bool -- ^ Put sections in div tags in HTML
91 , optSectionDivs :: Bool -- ^ Put sections in div tags in HTML
@@ -200,16 +200,17 @@ doOpt (k',v) = do
200 "output-file" ->
200 "output-file" ->
201 parseYAML v >>= \x -> return (\o -> o{ optOutputFile = unpack <$> x })
201 parseYAML v >>= \x -> return (\o -> o{ optOutputFile = unpack <$> x })
202 "input-files" ->
202 "input-files" ->
203− parseYAML v >>= \x -> return (\o -> o{ optInputFiles = optInputFiles o <>
203+ parseYAML v >>= \x -> return (\o -> o{ optInputFiles =
204+ optInputFiles o <>
204− map unpack x })
205+ Just (map unpack x) })
205 "input-file" -> -- allow either a list or a single value
206 "input-file" -> -- allow either a list or a single value
206 (parseYAML v >>= \x -> return (\o -> o{ optInputFiles =
207 (parseYAML v >>= \x -> return (\o -> o{ optInputFiles =
207 optInputFiles o <>
208 optInputFiles o <>
208− map unpack x }))
209+ Just (map unpack x) }))
209 <|>
210 <|>
210 (parseYAML v >>= \x -> return (\o -> o{ optInputFiles =
211 (parseYAML v >>= \x -> return (\o -> o{ optInputFiles =
211 optInputFiles o <>
212 optInputFiles o <>
212− [unpack x] }))
213+ Just [unpack x] }))
213 "number-sections" ->
214 "number-sections" ->
214 parseYAML v >>= \x -> return (\o -> o{ optNumberSections = x })
215 parseYAML v >>= \x -> return (\o -> o{ optNumberSections = x })
215 "number-offset" ->
216 "number-offset" ->
@@ -390,7 +391,7 @@ defaultOpts = Opt
390 , optMetadata = mempty
391 , optMetadata = mempty
391 , optMetadataFiles = []
392 , optMetadataFiles = []
392 , optOutputFile = Nothing
393 , optOutputFile = Nothing
393− , optInputFiles = []
394+ , optInputFiles = Nothing
394 , optNumberSections = False
395 , optNumberSections = False
395 , optNumberOffset = [0,0,0,0,0,0]
396 , optNumberOffset = [0,0,0,0,0,0]
396 , optSectionDivs = False
397 , optSectionDivs = False
src/Text/Pandoc/App/OutputSettings.hs+3−2
@@ -63,7 +63,7 @@ optToOutputSettings opts = do
63
63
64 when (optDumpArgs opts) . liftIO $ do
64 when (optDumpArgs opts) . liftIO $ do
65 UTF8.hPutStrLn stdout outputFile
65 UTF8.hPutStrLn stdout outputFile
66− mapM_ (UTF8.hPutStrLn stdout) (optInputFiles opts)
66+ mapM_ (UTF8.hPutStrLn stdout) (fromMaybe [] $ optInputFiles opts)
67 exitSuccess
67 exitSuccess
68
68
69 epubMetadata <- case optEpubMetadata opts of
69 epubMetadata <- case optEpubMetadata opts of
@@ -140,7 +140,8 @@ optToOutputSettings opts = do
140 variables <-
140 variables <-
141 return (optVariables opts)
141 return (optVariables opts)
142 >>=
142 >>=
143− setListVariableM "sourcefile" (T.pack <$> optInputFiles opts)
143+ setListVariableM "sourcefile"
144+ (maybe ["-"] (fmap T.pack) (optInputFiles opts))
144 >>=
145 >>=
145 setVariableM "outputfile" outputFile
146 setVariableM "outputfile" outputFile
146 >>=
147 >>=
test/command/lua-pandoc-state.md+1−1
@@ -2,7 +2,7 @@
2% pandoc --lua-filter=command/lua-pandoc-state.lua --data-dir=foo
2% pandoc --lua-filter=command/lua-pandoc-state.lua --data-dir=foo
3Hello
3Hello
4^D
4^D
5− # input files: 0
5+ # input files: 1
6 output file: nil
6 output file: nil
7# request header: 0
7# request header: 0
8 resource path: .
8 resource path: .