git.iko.soy/typeable/pandoc
on master help sign in
Fixed markdown2pdf.hs to accept --longopt=val options.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@1607 788f1e2b-df1e-0410-8736-df70ead52e1b

commit6191a1fa745c067d3df153b244e9829255600f5d authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 22 Aug 2009, 02:26 (17 years ago) parent69a84f7
1 file changed+14−9
src/markdown2pdf.hs+14−9
src/markdown2pdf.hs+14−9
@@ -1,6 +1,6 @@
11module Main where
22
3−import Data.List (isInfixOf, intercalate, (\\))
3+import Data.List (isInfixOf, intercalate, isPrefixOf)
44import Data.Maybe (isNothing)
55
66import Control.Monad (when, unless, guard)
@@ -155,21 +155,26 @@ main = bracket
155155 unless (null miss) $ exit $! "Could not find " ++ intercalate ", " miss
156156 args <- getArgs
157157 -- check for invalid arguments and print help message if needed
158− let goodopts = ["-f","-r","--from","--read","--strict","-N",
159− "-p","--preserve-tabs","--tab-stop","-R","--parse-raw",
158+ let goodopts = ["-f","-r","-N", "-p","-R","-H","-B","-A", "-C","-o"]
159+ let goodoptslong = ["--from","--read","--strict",
160+ "--preserve-tabs","--tab-stop","--parse-raw",
160161 "--toc","--table-of-contents",
161− "--number-sections","-H","--include-in-header",
162− "-B","--include-before-body","-A","--include-after-body",
163− "-C","--custom-header","-o","--output"]
164− let goodoptsLong = filter (\op -> length op > 2) goodopts
162+ "--number-sections","--include-in-header",
163+ "--include-before-body","--include-after-body",
164+ "--custom-header","--output"]
165165 let isOpt ('-':_) = True
166166 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
168172 (code, out, _err) <- readProcessWithExitCode "pandoc" ["--help"] ""
169173 putStrLn "markdown2pdf [OPTIONS] [FILES]\nOptions:"
170174 putStr $ unlines $
171− filter (\l -> any (`isInfixOf` l) goodoptsLong) $ lines out
175+ filter (\l -> any (`isInfixOf` l) goodoptslong) $ lines out
172176 exitWith code
177+
173178 -- parse arguments
174179 -- if no input given, use 'stdin'
175180 pandocArgs <- parsePandocArgs args