@@ -1,6 +1,6 @@
1module Main where
1module Main where
3−import Data.List (isInfixOf, intercalate, (\\))
3+import Data.List (isInfixOf, intercalate, isPrefixOf)
4import Data.Maybe (isNothing)
4import Data.Maybe (isNothing)
6import Control.Monad (when, unless, guard)
6import Control.Monad (when, unless, guard)
@@ -155,21 +155,26 @@ main = bracket
155 unless (null miss) $ exit $! "Could not find " ++ intercalate ", " miss
155 unless (null miss) $ exit $! "Could not find " ++ intercalate ", " miss
156 args <- getArgs
156 args <- getArgs
157 -- check for invalid arguments and print help message if needed
157 -- check for invalid arguments and print help message if needed
158− let goodopts = ["-f","-r","--from","--read","--strict","-N",
158+ let goodopts = ["-f","-r","-N", "-p","-R","-H","-B","-A", "-C","-o"]
159+ let goodoptslong = ["--from","--read","--strict",
159− "-p","--preserve-tabs","--tab-stop","-R","--parse-raw",
160+ "--preserve-tabs","--tab-stop","--parse-raw",
160 "--toc","--table-of-contents",
161 "--toc","--table-of-contents",
161− "--number-sections","-H","--include-in-header",
162+ "--number-sections","--include-in-header",
162− "-B","--include-before-body","-A","--include-after-body",
163+ "--include-before-body","--include-after-body",
163− "-C","--custom-header","-o","--output"]
164+ "--custom-header","--output"]
164− let goodoptsLong = filter (\op -> length op > 2) goodopts
165 let isOpt ('-':_) = True
165 let isOpt ('-':_) = True
166 isOpt _ = False
166 isOpt _ = False
167− unless (null (filter isOpt args \\ goodopts)) $ do
167+ let opts = filter isOpt args
168+ -- note that a long option can come in this form: --opt=val
169+ let isGoodopt x = x `elem` (goodopts ++ goodoptslong) ||
170+ any (\o -> (o ++ "=") `isPrefixOf` x) goodoptslong
171+ unless (all isGoodopt opts) $ do
168 (code, out, _err) <- readProcessWithExitCode "pandoc" ["--help"] ""
172 (code, out, _err) <- readProcessWithExitCode "pandoc" ["--help"] ""
169 putStrLn "markdown2pdf [OPTIONS] [FILES]\nOptions:"
173 putStrLn "markdown2pdf [OPTIONS] [FILES]\nOptions:"
170 putStr $ unlines $
174 putStr $ unlines $
171− filter (\l -> any (`isInfixOf` l) goodoptsLong) $ lines out
175+ filter (\l -> any (`isInfixOf` l) goodoptslong) $ lines out
172 exitWith code
176 exitWith code
173 -- parse arguments
178 -- parse arguments
174 -- if no input given, use 'stdin'
179 -- if no input given, use 'stdin'
175 pandocArgs <- parsePandocArgs args
180 pandocArgs <- parsePandocArgs args