@@ -111,7 +111,8 @@ data Opt = Opt
111 , optIncremental :: Bool -- ^ Use incremental lists in S5
111 , optIncremental :: Bool -- ^ Use incremental lists in S5
112 , optSmart :: Bool -- ^ Use smart typography
112 , optSmart :: Bool -- ^ Use smart typography
113 , optASCIIMathML :: Bool -- ^ Use ASCIIMathML in HTML
113 , optASCIIMathML :: Bool -- ^ Use ASCIIMathML in HTML
114− , optDebug :: Bool -- ^ Output debug messages
114+ , optDumpArgs :: Bool -- ^ Output command-line arguments
115+ , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
115 , optStrict :: Bool -- ^ Use strict markdown syntax
116 , optStrict :: Bool -- ^ Use strict markdown syntax
@@ -130,12 +131,13 @@ defaultOpts = Opt
130 , optIncludeAfterBody = ""
131 , optIncludeAfterBody = ""
131 , optCustomHeader = "DEFAULT"
132 , optCustomHeader = "DEFAULT"
132 , optTitlePrefix = ""
133 , optTitlePrefix = ""
133− , optOutputFile = "" -- null for stdout
134+ , optOutputFile = "-" -- "-" means stdout
134 , optNumberSections = False
135 , optNumberSections = False
135 , optIncremental = False
136 , optIncremental = False
136 , optSmart = False
137 , optSmart = False
137 , optASCIIMathML = False
138 , optASCIIMathML = False
138− , optDebug = False
139+ , optDumpArgs = False
140+ , optIgnoreArgs = False
139 , optStrict = False
141 , optStrict = False
@@ -267,10 +269,15 @@ options =
267 "FORMAT")
269 "FORMAT")
268 "" -- "Print default header for FORMAT"
270 "" -- "Print default header for FORMAT"
270− , Option "d" ["debug"]
272+ , Option "" ["dump-args"]
272− (\opt -> return opt { optDebug = True }))
274+ (\opt -> return opt { optDumpArgs = True }))
273− "" -- "Print debug messages to stderr, output to stdout"
275+ "" -- "Print output filename and arguments to stdout."
277+ , Option "" ["ignore-args"]
279+ (\opt -> return opt { optIgnoreArgs = True }))
280+ "" -- "Ignore command-line arguments."
275 , Option "v" ["version"]
282 , Option "v" ["version"]
@@ -278,7 +285,7 @@ options =
278 prg <- getProgName
285 prg <- getProgName
279 hPutStrLn stderr (prg ++ " " ++ version ++
286 hPutStrLn stderr (prg ++ " " ++ version ++
280 copyrightMessage)
287 copyrightMessage)
281− exitWith $ ExitFailure 2))
288+ exitWith $ ExitFailure 4))
282 "" -- "Print version"
289 "" -- "Print version"
284 , Option "h" ["help"]
291 , Option "h" ["help"]
@@ -317,7 +324,7 @@ defaultReaderName (x:xs) =
318-- Determine default writer based on output file extension
325-- Determine default writer based on output file extension
319defaultWriterName :: String -> String
326defaultWriterName :: String -> String
320−defaultWriterName "" = "html" -- no output file
327+defaultWriterName "-" = "html" -- no output file
321defaultWriterName x =
328defaultWriterName x =
322 let x' = map toLower x in
329 let x' = map toLower x in
323 case (matchRegex (mkRegex ".*\\.(.*)") x') of
330 case (matchRegex (mkRegex ".*\\.(.*)") x') of
@@ -341,20 +348,20 @@ defaultWriterName x =
344− args <- getArgs
351+ rawArgs <- getArgs
345 prg <- getProgName
352 prg <- getProgName
346 let compatMode = (prg == "hsmarkdown")
353 let compatMode = (prg == "hsmarkdown")
348− let (actions, sources, errors) = if compatMode
355+ let (actions, args, errors) = if compatMode
349− then ([], args, [])
356+ then ([], rawArgs, [])
350− else getOpt Permute options args
357+ else getOpt Permute options rawArgs
352 if (not (null errors))
359 if (not (null errors))
354 name <- getProgName
361 name <- getProgName
355 mapM (\e -> hPutStrLn stderr e) errors
362 mapM (\e -> hPutStrLn stderr e) errors
356 hPutStr stderr (usageMessage name options)
363 hPutStr stderr (usageMessage name options)
357− exitWith $ ExitFailure 2
364+ exitWith $ ExitFailure 3
359 return ()
366 return ()
@@ -384,10 +391,13 @@ main = do
384 , optIncremental = incremental
391 , optIncremental = incremental
385 , optSmart = smart
392 , optSmart = smart
386 , optASCIIMathML = asciiMathML
393 , optASCIIMathML = asciiMathML
387− , optDebug = debug
394+ , optDumpArgs = dumpArgs
395+ , optIgnoreArgs = ignoreArgs
388 , optStrict = strict
396 , optStrict = strict
399+ let sources = if ignoreArgs then [] else args
391 -- assign reader and writer based on options and filenames
401 -- assign reader and writer based on options and filenames
392 let readerName' = if null readerName
402 let readerName' = if null readerName
393 then defaultReaderName sources
403 then defaultReaderName sources
@@ -405,14 +415,15 @@ main = do
405 Just (w,h) -> return (w, h)
415 Just (w,h) -> return (w, h)
406 Nothing -> error ("Unknown writer: " ++ writerName')
416 Nothing -> error ("Unknown writer: " ++ writerName')
408− output <- if ((null outputFile) || debug)
418+ output <- if (outputFile == "-")
409 then return stdout
419 then return stdout
410 else openFile outputFile WriteMode
420 else openFile outputFile WriteMode
412− if debug
422+ if dumpArgs
414− hPutStrLn stderr ("OUTPUT=" ++ outputFile)
424+ hPutStrLn stdout outputFile
415− hPutStr stderr $ concatMap (\s -> "INPUT=" ++ s ++ "\n") sources
425+ mapM (\arg -> hPutStrLn stdout arg) args
426+ exitWith $ ExitSuccess
416 else return ()
427 else return ()
418 let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop)
429 let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop)