@@ -49,7 +49,7 @@ import Text.CSL
49import Text.Pandoc.Biblio
49import Text.Pandoc.Biblio
51import Text.Pandoc.Plugins (getPlugin)
51import Text.Pandoc.Plugins (getPlugin)
52−import Control.Monad (foldM)
52+import Control.Monad (foldM, when, unless)
54copyrightMessage :: String
54copyrightMessage :: String
55copyrightMessage = "\nCopyright (C) 2006-8 John MacFarlane\n" ++
55copyrightMessage = "\nCopyright (C) 2006-8 John MacFarlane\n" ++
@@ -98,7 +98,7 @@ readers = [("native" , readPandoc)
99-- | Reader for native Pandoc format.
99-- | Reader for native Pandoc format.
100readPandoc :: ParserState -> String -> Pandoc
100readPandoc :: ParserState -> String -> Pandoc
101−readPandoc _ input = read input
101+readPandoc _ = read
103-- | Association list of formats and pairs of writers and default headers.
103-- | Association list of formats and pairs of writers and default headers.
104writers :: [ ( String, ( WriterOptions -> Pandoc -> String, String ) ) ]
104writers :: [ ( String, ( WriterOptions -> Pandoc -> String, String ) ) ]
@@ -440,11 +440,10 @@ options =
441-- Returns usage message
441-- Returns usage message
442usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
442usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
443−usageMessage programName opts = usageInfo
443+usageMessage programName = usageInfo
444 (programName ++ " [OPTIONS] [FILES]" ++ "\nInput formats: " ++
444 (programName ++ " [OPTIONS] [FILES]" ++ "\nInput formats: " ++
445 (intercalate ", " $ map fst readers) ++ "\nOutput formats: " ++
445 (intercalate ", " $ map fst readers) ++ "\nOutput formats: " ++
446 (intercalate ", " $ map fst writers) ++ "\nOptions:")
446 (intercalate ", " $ map fst writers) ++ "\nOptions:")
449-- Determine default reader based on source file extensions
448-- Determine default reader based on source file extensions
450defaultReaderName :: [FilePath] -> String
449defaultReaderName :: [FilePath] -> String
@@ -505,14 +504,11 @@ main = do
505 then ([], rawArgs, [])
504 then ([], rawArgs, [])
506 else getOpt Permute options rawArgs
505 else getOpt Permute options rawArgs
508− if (not (null errors))
507+ unless (null errors) $
510− name <- getProgName
508+ do name <- getProgName
511− mapM (\e -> hPutStrLn stderr e) errors
509+ mapM_ (\e -> hPutStrLn stderr e) errors
512− hPutStr stderr (usageMessage name options)
510+ hPutStr stderr (usageMessage name options)
513− exitWith $ ExitFailure 2
511+ exitWith $ ExitFailure 2
517 let defaultOpts' = if compatMode
513 let defaultOpts' = if compatMode
518 then defaultOpts { optReader = "markdown"
514 then defaultOpts { optReader = "markdown"
@@ -556,12 +552,10 @@ main = do
559− if dumpArgs
555+ when dumpArgs $
561− hPutStrLn stdout outputFile
556+ do hPutStrLn stdout outputFile
562− mapM (\arg -> hPutStrLn stdout arg) args
557+ mapM_ (\arg -> hPutStrLn stdout arg) args
563− exitWith $ ExitSuccess
558+ exitWith ExitSuccess
566 let sources = if ignoreArgs then [] else args
560 let sources = if ignoreArgs then [] else args
@@ -588,18 +582,18 @@ main = do
588 Nothing -> stateColumns defaultParserState
582 Nothing -> stateColumns defaultParserState
590 let tabFilter _ [] = ""
584 let tabFilter _ [] = ""
591− tabFilter _ ('\n':xs) = '\n':(tabFilter tabStop xs)
585+ tabFilter _ ('\n':xs) = '\n' : tabFilter tabStop xs
592 -- remove DOS line endings
586 -- remove DOS line endings
593− tabFilter _ ('\r':'\n':xs) = '\n':(tabFilter tabStop xs)
587+ tabFilter _ ('\r':'\n':xs) = '\n' : tabFilter tabStop xs
594− tabFilter _ ('\r':xs) = '\n':(tabFilter tabStop xs)
588+ tabFilter _ ('\r':xs) = '\n' : tabFilter tabStop xs
595 tabFilter spsToNextStop ('\t':xs) =
589 tabFilter spsToNextStop ('\t':xs) =
596 if preserveTabs
590 if preserveTabs
597− then '\t':(tabFilter tabStop xs)
591+ then '\t' : tabFilter tabStop xs
598 else replicate spsToNextStop ' ' ++ tabFilter tabStop xs
592 else replicate spsToNextStop ' ' ++ tabFilter tabStop xs
599 tabFilter 1 (x:xs) =
593 tabFilter 1 (x:xs) =
600− x:(tabFilter tabStop xs)
594+ x : tabFilter tabStop xs
601 tabFilter spsToNextStop (x:xs) =
595 tabFilter spsToNextStop (x:xs) =
602− x:(tabFilter (spsToNextStop - 1) xs)
596+ x : tabFilter (spsToNextStop - 1) xs
604 let standalone' = (standalone && not strict) || isNonTextOutput writerName'
598 let standalone' = (standalone && not strict) || isNonTextOutput writerName'
@@ -627,7 +621,7 @@ main = do
627 (\f -> "<link rel=\"stylesheet\" href=\"" ++
621 (\f -> "<link rel=\"stylesheet\" href=\"" ++
628 f ++ "\" type=\"text/css\" media=\"all\" />\n")
622 f ++ "\" type=\"text/css\" media=\"all\" />\n")
630− let header = (if (customHeader == "DEFAULT")
624+ let header = (if customHeader == "DEFAULT"
631 then defaultHeader
625 then defaultHeader
632 else customHeader) ++ csslink ++ includeHeader
626 else customHeader) ++ csslink ++ includeHeader
633 let writerOptions = WriterOptions { writerStandalone = standalone',
627 let writerOptions = WriterOptions { writerStandalone = standalone',
@@ -635,7 +629,7 @@ main = do
635 writerTitlePrefix = titlePrefix,
629 writerTitlePrefix = titlePrefix,
636 writerTabStop = tabStop,
630 writerTabStop = tabStop,
637 writerTableOfContents = toc &&
631 writerTableOfContents = toc &&
638− (not strict) &&
632+ not strict &&
639 writerName' /= "s5",
633 writerName' /= "s5",
640 writerHTMLMathMethod = mathMethod,
634 writerHTMLMathMethod = mathMethod,
641 writerS5 = (writerName' == "s5"),
635 writerS5 = (writerName' == "s5"),
@@ -653,11 +647,10 @@ main = do
653 then ReferenceObfuscation
647 then ReferenceObfuscation
654 else obfuscationMethod }
648 else obfuscationMethod }
656− if isNonTextOutput writerName' && outputFile == "-"
650+ when (isNonTextOutput writerName' && outputFile == "-") $
657− then do hPutStrLn stderr ("Error: Cannot write " ++ writerName ++ " output to stdout.\n" ++
651+ do hPutStrLn stderr ("Error: Cannot write " ++ writerName ++ " output to stdout.\n" ++
658 "Specify an output file using the -o option.")
652 "Specify an output file using the -o option.")
659− exitWith $ ExitFailure 5
653+ exitWith $ ExitFailure 5
662 let sourceDirRelative = if null sources
655 let sourceDirRelative = if null sources