git.iko.soy/typeable/pandoc
on master help sign in
Added new Haskell version of markdown2pdf.

Thanks to Paulo Tanimoto for the patch. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1573 788f1e2b-df1e-0410-8736-df70ead52e1b

commitcceede4ca20f1f362b7bc6868618177f9c7b4bab authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateFri 1 May 2009, 04:18 (17 years ago) parent2d5f718
2 files changed+27−15
pandoc.cabal+11 src/markdown2pdf.hs+16−15
pandoc.cabal+11
@@ -232,3 +232,14 @@ Executable hsmarkdown
232232 else
233233 Buildable: False
234234
235+Executable markdown2pdf
236+ Hs-Source-Dirs: src
237+ Main-Is: markdown2pdf.hs
238+ Ghc-Options: -Wall -threaded
239+ Ghc-Prof-Options: -auto-all
240+ Extensions: CPP, TemplateHaskell
241+ if flag(wrappers)
242+ Buildable: True
243+ else
244+ Buildable: False
245+
src/markdown2pdf.hs+16−15
@@ -1,6 +1,6 @@
11module Main where
22
3−import Data.List (isInfixOf, intercalate, intersect)
3+import Data.List (isInfixOf, intercalate, (\\))
44import Data.Maybe (isNothing)
55
66import Control.Monad (when, unless, guard)
@@ -153,23 +153,24 @@ main = bracket
153153 paths <- mapM findExecutable execs
154154 let miss = map snd $ filter (isNothing . fst) $ zip paths execs
155155 unless (null miss) $ exit $! "Could not find " ++ intercalate ", " miss
156− -- parse arguments
157156 args <- getArgs
158− let badopts = ["-t","-w","--to","--write","-s","--standalone",
159− "--reference-links","-m","--latexmathml",
160− "--asciimathml","--mimetex","--jsmath","--gladtex",
161− "-i","--incremental","--no-wrap", "--sanitize-html",
162− "--email-obfuscation","-c","--css","-T","--title-prefix",
163− "-D","--print-default-header","--dump-args",
164− "--ignore-args","-h","--help","-v","--version"]
165− let badoptsLong = filter (\o -> length o > 2) badopts
166− unless (null (args `intersect` badopts)) $ do
157+ -- 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",
160+ "--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
165+ let isOpt ('-':_) = True
166+ isOpt _ = False
167+ unless (null (filter isOpt args \\ goodopts)) $ do
167168 (code, out, _err) <- readProcessWithExitCode "pandoc" ["--help"] ""
168− putStrLn "markdown2pdf [OPTIONS] [FILES]"
169− putStrLn $ unlines $ drop 3 $
170− filter (\l -> not . any (`isInfixOf` l) $ badoptsLong) $
171− lines out
169+ putStrLn "markdown2pdf [OPTIONS] [FILES]\nOptions:"
170+ putStr $ unlines $
171+ filter (\l -> any (`isInfixOf` l) goodoptsLong) $ lines out
172172 exitWith code
173+ -- parse arguments
173174 pandocArgs <- parsePandocArgs args
174175 (inputs, output) <- case pandocArgs of
175176 Nothing -> exit "Could not parse arguments"