@@ -111,7 +111,8 @@ data Opt = Opt
111111 , optIncremental :: Bool -- ^ Use incremental lists in S5
112112 , optSmart :: Bool -- ^ Use smart typography
113113 , 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
115116 , optStrict :: Bool -- ^ Use strict markdown syntax
116117 }
117118
@@ -130,12 +131,13 @@ defaultOpts = Opt
130131 , optIncludeAfterBody = ""
131132 , optCustomHeader = "DEFAULT"
132133 , optTitlePrefix = ""
133− , optOutputFile = "" -- null for stdout
134+ , optOutputFile = "-" -- "-" means stdout
134135 , optNumberSections = False
135136 , optIncremental = False
136137 , optSmart = False
137138 , optASCIIMathML = False
138− , optDebug = False
139+ , optDumpArgs = False
140+ , optIgnoreArgs = False
139141 , optStrict = False
140142 }
141143
@@ -267,10 +269,15 @@ options =
267269 "FORMAT")
268270 "" -- "Print default header for FORMAT"
269271
270− , Option "d" ["debug"]
272+ , Option "" ["dump-args"]
271273 (NoArg
272− (\opt -> return opt { optDebug = True }))
273− "" -- "Print debug messages to stderr, output to stdout"
274+ (\opt -> return opt { optDumpArgs = True }))
275+ "" -- "Print output filename and arguments to stdout."
276+
277+ , Option "" ["ignore-args"]
278+ (NoArg
279+ (\opt -> return opt { optIgnoreArgs = True }))
280+ "" -- "Ignore command-line arguments."
274281
275282 , Option "v" ["version"]
276283 (NoArg
@@ -278,7 +285,7 @@ options =
278285 prg <- getProgName
279286 hPutStrLn stderr (prg ++ " " ++ version ++
280287 copyrightMessage)
281− exitWith $ ExitFailure 2))
288+ exitWith $ ExitFailure 4))
282289 "" -- "Print version"
283290
284291 , Option "h" ["help"]
@@ -317,7 +324,7 @@ defaultReaderName (x:xs) =
317324
318325-- Determine default writer based on output file extension
319326defaultWriterName :: String -> String
320−defaultWriterName "" = "html" -- no output file
327+defaultWriterName "-" = "html" -- no output file
321328defaultWriterName x =
322329 let x' = map toLower x in
323330 case (matchRegex (mkRegex ".*\\.(.*)") x') of
@@ -341,20 +348,20 @@ defaultWriterName x =
341348
342349main = do
343350
344− args <- getArgs
351+ rawArgs <- getArgs
345352 prg <- getProgName
346353 let compatMode = (prg == "hsmarkdown")
347354
348− let (actions, sources, errors) = if compatMode
349− then ([], args, [])
350− else getOpt Permute options args
355+ let (actions, args, errors) = if compatMode
356+ then ([], rawArgs, [])
357+ else getOpt Permute options rawArgs
351358
352359 if (not (null errors))
353360 then do
354361 name <- getProgName
355362 mapM (\e -> hPutStrLn stderr e) errors
356363 hPutStr stderr (usageMessage name options)
357− exitWith $ ExitFailure 2
364+ exitWith $ ExitFailure 3
358365 else
359366 return ()
360367
@@ -384,10 +391,13 @@ main = do
384391 , optIncremental = incremental
385392 , optSmart = smart
386393 , optASCIIMathML = asciiMathML
387− , optDebug = debug
394+ , optDumpArgs = dumpArgs
395+ , optIgnoreArgs = ignoreArgs
388396 , optStrict = strict
389397 } = opts
390398
399+ let sources = if ignoreArgs then [] else args
400+
391401 -- assign reader and writer based on options and filenames
392402 let readerName' = if null readerName
393403 then defaultReaderName sources
@@ -405,14 +415,15 @@ main = do
405415 Just (w,h) -> return (w, h)
406416 Nothing -> error ("Unknown writer: " ++ writerName')
407417
408− output <- if ((null outputFile) || debug)
418+ output <- if (outputFile == "-")
409419 then return stdout
410420 else openFile outputFile WriteMode
411421
412− if debug
413− then do
414− hPutStrLn stderr ("OUTPUT=" ++ outputFile)
415− hPutStr stderr $ concatMap (\s -> "INPUT=" ++ s ++ "\n") sources
422+ if dumpArgs
423+ then do
424+ hPutStrLn stdout outputFile
425+ mapM (\arg -> hPutStrLn stdout arg) args
426+ exitWith $ ExitSuccess
416427 else return ()
417428
418429 let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop)