git.iko.soy/typeable/pandoc
on master help sign in
Removed markdown2pdf and documentation.
commit1d615908c2c346c034aa63f572f5f112638d8ff4 authorJohn MacFarlane <fiddlosopher@gmail.com> dateFri 20 Jan 2012, 21:22 (15 years ago) parentb4a6c02
7 files changed+27−487
MakeManPage.hs−10 README+22−40 Setup.hs+4−19 man/man1/markdown2pdf.1.md−120 pandoc.cabal+1−28 src/markdown2pdf.hs−269 windows/make-windows-installer.bat−1
MakeManPage.hs−10
@@ -24,16 +24,6 @@ main = do
2424 meta manBlocks
2525 makeManPage verbose ("man" </> "man5" </> "pandoc_markdown.5")
2626 meta syntaxBlocks
27− let markdown2pdfpage = "man" </> "man1" </> "markdown2pdf.1"
28− modDeps <- modifiedDependencies markdown2pdfpage [markdown2pdfpage <.> "md"]
29− unless (null modDeps) $ do
30− mpdfContents <- liftM toString $ B.readFile $ markdown2pdfpage <.> "md"
31− templ <- liftM toString $ B.readFile $ "templates" </> "default.man"
32− let doc = readMarkdown defaultParserState{ stateStandalone = True }
33− mpdfContents
34− writeManPage markdown2pdfpage templ doc
35− when verbose $
36− putStrLn $ "Created " ++ markdown2pdfpage
3727
3828makeManPage :: Bool -> FilePath -> Meta -> [Block] -> IO ()
3929makeManPage verbose page meta blocks = do
README+22−40
@@ -17,7 +17,8 @@ and [LaTeX]; and it can write plain text, [markdown], [reStructuredText],
1717[XHTML], [HTML 5], [LaTeX], [LaTeX beamer], [ConTeXt], [RTF], [DocBook XML],
1818[OpenDocument XML], [ODT], [Word docx], [GNU Texinfo], [MediaWiki markup], [EPUB],
1919[Textile], [groff man] pages, [Emacs Org-Mode], [AsciiDoc], and [Slidy],
20−[DZSlides], or [S5] HTML slide shows.
20+[DZSlides], or [S5] HTML slide shows. It can also produce [PDF] output
21+on systems where LaTeX is installed.
2122
2223Pandoc's enhanced version of markdown includes syntax for footnotes,
2324tables, flexible ordered lists, definition lists, delimited code blocks,
@@ -34,14 +35,15 @@ representation of the document, and a set of writers, which convert
3435this native representation into a target format. Thus, adding an input
3536or output format requires only adding a reader or writer.
3637
37−Using Pandoc
38−------------
38+Using `pandoc`
39+--------------
3940
4041If no *input-file* is specified, input is read from *stdin*.
4142Otherwise, the *input-files* are concatenated (with a blank
4243line between each) and used as input. Output goes to *stdout* by
4344default (though output to *stdout* is disabled for the `odt`, `docx`,
44−and `epub` output formats). For output to a file, use the `-o` option:
45+`pdf`, and `epub` output formats). For output to a file, use the
46+`-o` option:
4547
4648 pandoc -o output.html input.txt
4749
@@ -89,36 +91,15 @@ should pipe input and output through `iconv`:
8991
9092 iconv -t utf-8 input.txt | pandoc | iconv -f utf-8
9193
92−Wrappers
93−========
94−
9594`markdown2pdf`
9695--------------
9796
98−The standard Pandoc installation includes `markdown2pdf`, a wrapper
99−around `pandoc` and `pdflatex` that produces PDFs directly from markdown
100−sources. The default behavior of `markdown2pdf` is to create a file with
101−the same base name as the first argument and the extension `pdf`; thus,
102−for example,
103−
104− markdown2pdf sample.txt endnotes.txt
105−
106−will produce `sample.pdf`. An output file
107−name can be specified explicitly using the `-o` option:
108−
109− markdown2pdf -o book.pdf chap1 chap2
110−
111−If no input file is specified, input will be taken from *stdin*.
112−All of `pandoc`'s options will work with `markdown2pdf` as well.
113−
114−`markdown2pdf` assumes that `pdflatex` is in the path. It also
115−assumes that the following LaTeX packages are available:
116−`unicode`, `fancyhdr` (if you have verbatim text in footnotes),
117−`graphicx` (if you use images), `array` (if you use tables),
118−and `ulem` (if you use strikeout text). If they are not already
119−included in your LaTeX distribution, you can get them from
120−[CTAN]. A full [TeX Live] or [MacTeX] distribution will have all of
121−these packages.
97+Earlier versions of pandoc came with a program, `markdown2pdf`,
98+that used pandoc and pdflatex to produce a PDF. This is no
99+longer needed, since `pandoc` now has a `pdf` output format.
100+Note that whereas `markdown2pdf` would create an ouput file
101+based on the input file name, `pandoc` requires that you specify
102+the output filename explicitly.
122103
123104`hsmarkdown`
124105------------
@@ -158,12 +139,12 @@ Options
158139 (DocBook XML), `opendocument` (OpenDocument XML), `odt` (OpenOffice text
159140 document), `docx` (Word docx), `epub` (EPUB book), `asciidoc` (AsciiDoc),
160141 `slidy` (Slidy HTML and javascript slide show), `dzslides` (HTML5 +
161− javascript slide show), `s5` (S5 HTML and javascript slide show), or
162− `rtf` (rich text format). Note that `odt` and `epub` output will not be
163− directed to *stdout*; an output filename must be specified using the
164− `-o/--output` option. If `+lhs` is appended to `markdown`, `rst`, `latex`,
165− `html`, or `html5`, the output will be rendered as literate Haskell source:
166− see [Literate Haskell support](#literate-haskell-support), below.
142+ javascript slide show), `s5` (S5 HTML and javascript slide show),
143+ `rtf` (rich text format), or `pdf` (PDF). Note that `odt` and `epub` output
144+ will not be directed to *stdout*; an output filename must be specified
145+ using the `-o/--output` option. If `+lhs` is appended to `markdown`, `rst`,
146+ `latex`, `html`, or `html5`, the output will be rendered as literate Haskell
147+ source: see [Literate Haskell support](#literate-haskell-support), below.
167148
168149`-s`, `--standalone`
169150: Produce output with an appropriate header and footer (e.g. a
@@ -172,7 +153,7 @@ Options
172153`-o` *FILE*, `--output=`*FILE*
173154: Write output to *FILE* instead of *stdout*. If *FILE* is
174155 `-`, output will go to *stdout*. (Exception: if the output
175− format is `odt`, `docx`, or `epub`, output to stdout is disabled.)
156+ format is `odt`, `docx`, `pdf`, or `epub`, output to stdout is disabled.)
176157
177158`-p`, `--preserve-tabs`
178159: Preserve tabs instead of converting them to spaces (the default).
@@ -1937,8 +1918,8 @@ Producing slide shows with Pandoc
19371918You can use Pandoc to produce an HTML + javascript slide presentation
19381919that can be viewed via a web browser. There are three ways to do this,
19391920using [S5], [DZSlides], or [Slidy]. You can also produce a PDF slide
1940−show using [LaTeX beamer]: just pass the `--beamer` option to
1941−`markdown2pdf`.
1921+show using [LaTeX beamer]: just use the `--beamer` option with `pdf`
1922+output.
19421923
19431924Here's the markdown source for a simple slide show, `eating.txt`:
19441925
@@ -2094,3 +2075,4 @@ Christopher Sawicki, Kelsey Hightower.
20942075[DZSlides]: http://paulrouget.com/dzslides/
20952076[ISO 8601 format]: http://www.w3.org/TR/NOTE-datetime
20962077[Word docx]: http://www.microsoft.com/interop/openup/openxml/default.aspx
2078+[PDF]: http://www.adobe.com/pdf/
Setup.hs+4−19
@@ -25,14 +25,11 @@ main = do
2525 defaultMainWithHooks $ simpleUserHooks {
2626 runTests = runTestSuite
2727 , postBuild = makeManPages
28− , postCopy = \ _ flags pkg lbi -> do
28+ , postCopy = \ _ flags pkg lbi ->
2929 installManpages pkg lbi (fromFlag $ copyVerbosity flags)
3030 (fromFlag $ copyDest flags)
31− installScripts pkg lbi (fromFlag $ copyVerbosity flags)
32− (fromFlag $ copyDest flags)
33− , postInst = \ _ flags pkg lbi -> do
31+ , postInst = \ _ flags pkg lbi ->
3432 installManpages pkg lbi (fromFlag $ installVerbosity flags) NoCopyDest
35− installScripts pkg lbi (fromFlag $ installVerbosity flags) NoCopyDest
3633 }
3734 exitWith ExitSuccess
3835
@@ -53,9 +50,7 @@ makeManPages :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO
5350makeManPages _ flags _ lbi = do
5451 ds1 <- modifiedDependencies (manDir </> "man1" </> "pandoc.1")
5552 ["README", manDir </> "man1" </> "pandoc.1.template"]
56− ds2 <- modifiedDependencies (manDir </> "man1" </> "markdown2pdf.1")
57− [manDir </> "man1" </> "markdown2pdf.1.md"]
58− ds3 <- modifiedDependencies (manDir </> "man5" </> "pandoc_markdown.5")
53+ ds2 <- modifiedDependencies (manDir </> "man5" </> "pandoc_markdown.5")
5954 ["README", manDir </> "man5" </> "pandoc_markdown.5.template"]
6055
6156 let distPref = fromFlag (buildDistPref flags)
@@ -71,7 +66,7 @@ makeManPages _ flags _ lbi = do
7166 then args
7267 else args ++ ["--verbose"]
7368 -- Don't run MakeManPage.hs unless we have to
74− unless (null ds1 && null ds2 && null ds3) $ do
69+ unless (null ds1 && null ds2) $ do
7570 rawSystem "runghc" args' >>= exitWith
7671
7772-- format arguments to runghc that we wish to pass to ghc
@@ -83,21 +78,11 @@ makeGhcArgs = map ("--ghc-arg="++)
8378
8479manpages :: [FilePath]
8580manpages = ["man1" </> "pandoc.1"
86− ,"man1" </> "markdown2pdf.1"
8781 ,"man5" </> "pandoc_markdown.5"]
8882
8983manDir :: FilePath
9084manDir = "man"
9185
92−installScripts :: PackageDescription -> LocalBuildInfo
93− -> Verbosity -> CopyDest -> IO ()
94−installScripts pkg lbi verbosity copy =
95− copyFiles verbosity (bindir (absoluteInstallDirs pkg lbi copy))
96− (zip (repeat ".") (wrappers \\ exes))
97− where exes = map exeName $ filter isBuildable $ executables pkg
98− isBuildable = buildable . buildInfo
99− wrappers = ["markdown2pdf"]
100−
10186installManpages :: PackageDescription -> LocalBuildInfo
10287 -> Verbosity -> CopyDest -> IO ()
10388installManpages pkg lbi verbosity copy =
man/man1/markdown2pdf.1.mddeleted−120
@@ -1,120 +0,0 @@
1−% MARKDOWN2PDF(1) Pandoc User Manuals
2−% John MacFarlane, Paulo Tanimoto, and Recai Oktas
3−% January 29, 2011
4−
5−# NAME
6−
7−markdown2pdf - converts markdown-formatted text to PDF, using pdflatex
8−
9−# SYNOPSIS
10−
11−markdown2pdf [*options*] [*input-file*]...
12−
13−# DESCRIPTION
14−
15−`markdown2pdf` converts *input-file* (or text from standard
16−input) from markdown-formatted plain text to PDF, using `pandoc`
17−and `pdflatex`. If no output filename is specified (using the `-o`
18−option), the name of the output file is derived from the input file;
19−thus, for example, if the input file is *hello.txt*, the output file
20−will be *hello.pdf*. If the input is read from STDIN and no output
21−filename is specified, the output file will be named *stdin.pdf*. If
22−multiple input files are specified, they will be concatenated before
23−conversion, and the name of the output file will be derived from the
24−first input file.
25−
26−Input is assumed to be in the UTF-8 character encoding. If your
27−local character encoding is not UTF-8, you should pipe input
28−through `iconv`:
29−
30− iconv -t utf-8 input.txt | markdown2pdf
31−
32−`markdown2pdf` assumes that the `unicode`, `array`, `fancyvrb`,
33−`graphicx`, and `ulem` packages are in latex's search path. If these
34−packages are not included in your latex setup, they can be obtained from
35−<http://ctan.org>.
36−
37−# OPTIONS
38−
39−-o *FILE*, \--output=*FILE*
40−: Write output to *FILE*.
41−
42−\--strict
43−: Use strict markdown syntax, with no extensions or variants.
44−
45−-N, \--number-sections
46−: Number section headings in LaTeX output. (Default is not to number them.)
47−
48−\--listings
49−: Use listings package for LaTeX code blocks
50−
51−\--template=*FILE*
52−: Use *FILE* as a custom template for the generated document. Implies
53− `-s`. See the section TEMPLATES in `pandoc`(1) for information about
54− template syntax. Use `pandoc -D latex` to print the default LaTeX
55− template.
56−
57−-V KEY=VAL, \--variable=*KEY:VAL*
58−: Set the template variable KEY to the value VAL when rendering the
59− document in standalone mode. Use this to set the font size when
60− using the default LaTeX template: `-V fontsize=12pt`.
61−
62−-H *FILE*, \--include-in-header=*FILE*
63−: Include (LaTeX) contents of *FILE* at the end of the header. Implies
64− `-s`.
65−
66−-B *FILE*, \--include-before-body=*FILE*
67−: Include (LaTeX) contents of *FILE* at the beginning of the document body.
68−
69−-A *FILE*, \--include-after-body=*FILE*
70−: Include (LaTeX) contents of *FILE* at the end of the document body.
71−
72−\--bibliography=*FILE*
73−: Specify bibliography database to be used in resolving
74− citations. The database type will be determined from the
75− extension of *FILE*, which may be `.xml` (MODS format),
76− `.bib` (BibTeX format), or `.json` (citeproc JSON).
77−
78−\--csl=*FILE*
79−: Specify [CSL] style to be used in formatting citations and
80− the bibliography. If *FILE* is not found, pandoc will look
81− for it in
82−
83− $HOME/.csl
84−
85− in unix and
86−
87− C:\Documents And Settings\USERNAME\Application Data\csl
88−
89− in Windows. If the `--csl` option is not specified, pandoc
90− will use a default style: either `default.csl` in the
91− user data directory (see `--data-dir`), or, if that is
92− not present, the Chicago author-date style.
93−
94−\--data-dir*=DIRECTORY*
95−: Specify the user data directory to search for pandoc data files.
96− If this option is not specified, the default user data directory
97− will be used:
98−
99− $HOME/.pandoc
100−
101− in unix and
102−
103− C:\Documents And Settings\USERNAME\Application Data\pandoc
104−
105− in Windows. A `reference.odt`, `epub.css`, `templates` directory,
106− or `s5` directory placed in this directory will override pandoc's
107− normal defaults.
108−
109−\--xetex
110−: Use xelatex instead of pdflatex to create the PDF.
111−
112−\--luatex
113−: Use lualatex instead of pdflatex to create the PDF.
114−
115−# SEE ALSO
116−
117−`pandoc`(1), `pdflatex`(1)
118−
119−[CSL]: CitationStyles.org
120−
pandoc.cabal+1−28
@@ -84,14 +84,11 @@ Data-Files:
8484 -- documentation
8585 README, INSTALL, COPYRIGHT, BUGS, changelog
8686Extra-Source-Files:
87− -- sources for man pages
88− man/man1/markdown2pdf.1.md,
8987 -- code to create pandoc.1 man page
9088 MakeManPage.hs,
9189 man/man1/pandoc.1.template,
9290 man/man5/pandoc_markdown.5.template,
9391 -- generated man pages (produced post-build)
94− man/man1/markdown2pdf.1,
9592 man/man1/pandoc.1,
9693 man/man5/pandoc_markdown.5,
9794 -- benchmarks
@@ -174,31 +171,21 @@ Extra-Source-Files:
174171 tests/lhs-test.nohl.html+lhs,
175172 tests/lhs-test.fragment.html+lhs
176173Extra-Tmp-Files: man/man1/pandoc.1,
177− man/man1/markdown2pdf.1,
178174 man/man5/pandoc_markdown.5
179175
180176Source-repository head
181177 type: git
182178 location: git://github.com/jgm/pandoc.git
183179
184−Flag threaded
185− Description: Compile markdown2pdf with -threaded option.
186− Default: True
187180Flag executable
188181 Description: Build the pandoc executable.
189182 Default: True
190183Flag library
191184 Description: Build the pandoc library.
192185 Default: True
193−Flag wrappers
194− Description: Build the wrappers (markdown2pdf).
195− Default: True
196186Flag tests
197187 Description: Build test-pandoc.
198188 Default: False
199−Flag benchmarks
200− Description: Build benchmark-pandoc.
201− Default: False
202189
203190Library
204191 -- Note: the following material must be in both Library and Executable stanzas.
@@ -334,21 +321,7 @@ Executable pandoc
334321 -- END DUPLICATED SECTION
335322
336323 Main-Is: pandoc.hs
337− if flag(executable) || flag(wrappers)
338− Buildable: True
339− else
340− Buildable: False
341−
342−Executable markdown2pdf
343− Hs-Source-Dirs: src
344− Main-Is: markdown2pdf.hs
345− if flag(threaded)
346− Ghc-Options: -Wall -threaded
347− else
348− Ghc-Options: -Wall
349− Ghc-Prof-Options: -auto-all -rtsopts
350− Extensions: CPP
351− if flag(wrappers)
324+ if flag(executable)
352325 Buildable: True
353326 else
354327 Buildable: False
src/markdown2pdf.hsdeleted−269
@@ -1,269 +0,0 @@
1−module Main where
2−
3−import Data.List (isInfixOf, intercalate, isPrefixOf)
4−import Data.Maybe (isNothing)
5−import qualified Data.ByteString as BS
6−import Codec.Binary.UTF8.String (decodeString, encodeString)
7−import Data.ByteString.UTF8 (toString)
8−import Control.Monad (unless, guard, liftM, when)
9−import Control.Concurrent (putMVar, takeMVar, newEmptyMVar, forkIO)
10−import Control.Exception (tryJust, bracket, evaluate)
11−import Control.Monad.Trans (liftIO)
12−import System.IO.Error (isAlreadyExistsError)
13−
14−import System.IO
15−import System.IO.Error (isDoesNotExistError)
16−import System.Environment ( getArgs, getProgName )
17−import qualified Text.Pandoc.UTF8 as UTF8
18−import System.Exit (ExitCode (..), exitWith)
19−import System.FilePath
20−import System.Directory
21−import System.Process
22−
23−-- A variant of 'readProcessWithExitCode' that does not
24−-- cause an error if the output is not UTF-8. (Copied
25−-- with slight variants from 'System.Process'.)
26−readProcessWithExitCode'
27− :: FilePath -- ^ command to run
28− -> [String] -- ^ any arguments
29− -> String -- ^ standard input
30− -> IO (ExitCode,String,String) -- ^ exitcode, stdout, stderr
31−readProcessWithExitCode' cmd args input = do
32− (Just inh, Just outh, Just errh, pid) <-
33− createProcess (proc cmd args){ std_in = CreatePipe,
34− std_out = CreatePipe,
35− std_err = CreatePipe }
36−
37− outMVar <- newEmptyMVar
38−
39− -- fork off a thread to start consuming stdout
40− out <- liftM toString $ BS.hGetContents outh
41− _ <- forkIO $ evaluate (length out) >> putMVar outMVar ()
42−
43− -- fork off a thread to start consuming stderr
44− err <- liftM toString $ BS.hGetContents errh
45− _ <- forkIO $ evaluate (length err) >> putMVar outMVar ()
46−
47− -- now write and flush any input
48− when (not (null input)) $ do hPutStr inh input; hFlush inh
49− hClose inh -- done with stdin
50−
51− -- wait on the output
52− takeMVar outMVar
53− takeMVar outMVar
54− hClose outh
55−
56− -- wait on the process
57− ex <- waitForProcess pid
58−
59− return (ex, out, err)
60−
61−run :: FilePath -> [String] -> IO (Either String String)
62−run file opts = do
63− (code, out, err) <- readProcessWithExitCode' (encodeString file)
64− (map encodeString opts) ""
65− let msg = out ++ err
66− case code of
67− ExitFailure _ -> return $ Left $! msg
68− ExitSuccess -> return $ Right $! msg
69−
70−parsePandocArgs :: [String] -> IO (Maybe ([String], String))
71−parsePandocArgs args = do
72− result <- run "pandoc" $ ["--dump-args"] ++ args
73− return $ either error (parse . map trim . lines) result
74− where parse [] = Nothing
75− parse ("-":[]) = Just ([], "stdin") -- no output or input
76− parse ("-":x:xs) = Just (x:xs, dropExtension x) -- no output
77− parse ( x :xs) = Just (xs, dropExtension x) -- at least output
78− --trim = reverse . dropWhile isSpace . reverse . dropWhile isSpace
79− trim = takeWhile (/='\r') . dropWhile (=='\r')
80−
81−runPandoc :: String -> [String] -> FilePath -> IO (Either String FilePath)
82−runPandoc outputFormat inputsAndArgs output = do
83− let texFile = addExtension output "tex"
84− result <- run "pandoc" $
85− ["-s", "--no-wrap", "-r", "markdown", "-w", outputFormat]
86− ++ inputsAndArgs ++ ["-o", texFile]
87− return $ either Left (const $ Right texFile) result
88−
89−runLatexRaw :: String -> FilePath -> IO (Either (Either String String) FilePath)
90−runLatexRaw latexProgram file = do
91− -- we ignore the ExitCode because pdflatex always fails the first time
92− run latexProgram ["-halt-on-error", "-interaction", "nonstopmode",
93− "-output-directory", takeDirectory file, dropExtension file] >> return ()
94− let pdfFile = replaceExtension file "pdf"
95− let logFile = replaceExtension file "log"
96− txt <- tryJust (guard . isDoesNotExistError)
97− (liftM toString $ BS.readFile logFile)
98− let checks = checkLatex $ either (const "") id txt
99− case checks of
100− -- err , bib , ref , msg
101− (True , _ , _ , msg) -> return $ Left $ Left msg -- failure
102− (False, True , _ , msg) -> runBibtex file >>
103− (return $ Left $ Right msg) -- citations
104− (False, _ , True, msg) -> return $ Left $ Right msg -- references
105− (False, False, False, _ ) -> return $ Right pdfFile -- success
106−
107−runLatex :: String -> FilePath -> IO (Either String FilePath)
108−runLatex latexProgram file = step 3
109− where
110− step n = do
111− result <- runLatexRaw latexProgram file
112− case result of
113− Left (Left err) -> return $ Left err
114− Left (Right _) | n > 1 -> step (n-1 :: Int)
115− Right _ | n > 2 -> step (n-1 :: Int)
116− Left (Right msg) -> return $ Left msg
117− Right pdfFile -> return $ Right pdfFile
118−
119−checkLatex :: String -> (Bool, Bool, Bool, String)
120−checkLatex "" = (True, False, False, "Could not read log file")
121−checkLatex txt = (err , bib, ref, unlines $! msgs ++ tips)
122− where
123− xs `oneOf` x = any (flip isInfixOf x) xs
124− msgs = dropWhile (not . errorline) $ lines txt
125− errorline ('!':_) = True
126− errorline _ = False
127− tips = checkPackages msgs
128− err = any (oneOf ["!", "LaTeX Error:", "Latex Error:"]) msgs
129− bib = any (oneOf ["Warning: Citation"
130− ,"Warning: There were undefined citations"]) msgs
131− ref = any (oneOf ["Warning: Reference"
132− ,"Warning: Label"
133− ,"Warning: There were undefined references"
134− ]) msgs
135−
136−checkPackages :: [String] -> [String]
137−checkPackages = concatMap chks
138− where -- for each message, search 'pks' for matches and give a hint
139− chks x = concatMap (chk x) pks
140− chk x (k,v) = if sub k `isInfixOf` x then tip k v else []
141− sub k = "`" ++ k ++ ".sty' not found"
142− tip k v = ["Please install the '" ++ k ++
143− "' package from CTAN:", " " ++ v]
144− pks = [("ucs"
145− ,"http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/")
146− ,("ulem"
147− ,"http://www.ctan.org/tex-archive/macros/latex/contrib/misc/")
148− ,("graphicx"
149− ,"http://www.ctan.org/tex-archive/macros/latex/required/graphics/")
150− ,("fancyhdr"
151− ,"http://www.ctan.org/tex-archive/macros/latex/contrib/fancyhdr/")
152− ,("array"
153− ,"http://www.ctan.org/tex-archive/macros/latex/required/tools/")]
154−
155−runBibtex :: FilePath -> IO (Either String FilePath)
156−runBibtex file = do
157− let auxFile = replaceExtension file "aux"
158− result <- run "bibtex" [auxFile]
159− return $ either Left (const $ Right auxFile) result
160−
161−exit :: String -> IO a
162−exit x = do
163− progName <- getProgName
164− UTF8.hPutStrLn stderr $ progName ++ ": " ++ x
165− exitWith $ ExitFailure 1
166−
167−saveStdin :: FilePath -> IO (Either String FilePath)
168−saveStdin file = do
169− text <- liftM toString $ BS.getContents
170− UTF8.writeFile file text
171− fileExist <- doesFileExist (encodeString file)
172− case fileExist of
173− False -> return $ Left $! "Could not create " ++ file
174− True -> return $ Right file
175−
176−saveOutput :: FilePath -> FilePath -> IO ()
177−saveOutput input output = do
178− copyFile (encodeString input) (encodeString output)
179− UTF8.hPutStrLn stderr $! "Created " ++ output
180−
181−-- | Perform a function in a temporary directory and clean up.
182−withTempDir :: FilePath -> (FilePath -> IO a) -> IO a
183−withTempDir baseName = bracket (createTempDir 0 baseName) removeDirectoryRecursive
184−
185−-- | Create a temporary directory with a unique name.
186−createTempDir :: Integer -> FilePath -> IO FilePath
187−createTempDir num baseName = do
188− sysTempDir <- getTemporaryDirectory
189− let dirName = sysTempDir </> baseName <.> show num
190− liftIO $ catch (createDirectory dirName >> return dirName) $
191− \e -> if isAlreadyExistsError e
192− then createTempDir (num + 1) baseName
193− else ioError e
194−
195−main :: IO ()
196−main = withTempDir "pandoc"
197− -- run computation
198− $ \tmp -> do
199− args <- liftM (map decodeString) getArgs
200− -- check for invalid arguments and print help message if needed
201− let goodopts = ["-f","-r","-N", "-p","-R","-H","-B","-A", "-C","-o","-V"]
202− let goodoptslong = ["--from","--read","--strict",
203− "--preserve-tabs","--tab-stop","--parse-raw",
204− "--toc","--table-of-contents", "--xetex", "--luatex",
205− "--number-sections","--include-in-header",
206− "--include-before-body","--include-after-body",
207− "--custom-header","--output",
208− "--template", "--variable",
209− "--no-highlight", "--highlight-style",
210− "--citation-abbreviations", "--old-dashes",
211− "--csl", "--bibliography", "--data-dir", "--listings",
212− "--beamer"]
213− let isOpt ('-':_) = True
214− isOpt _ = False
215− let opts = filter isOpt args
216− -- note that a long option can come in this form: --opt=val
217− let isGoodopt x = x `elem` (goodopts ++ goodoptslong) ||
218− any (\o -> (o ++ "=") `isPrefixOf` x) goodoptslong
219− let markdown2pdfOpts = ["--xetex","--luatex", "--beamer"]
220− unless (all isGoodopt opts) $ do
221− (code, out, _err) <- readProcessWithExitCode "pandoc" ["--help"] ""
222− UTF8.putStrLn "markdown2pdf [OPTIONS] [FILES]\nOptions:"
223− UTF8.putStr $ unlines $
224− filter (\l -> any (`isInfixOf` l) goodoptslong) (lines out)
225− ++ map (replicate 24 ' ' ++) markdown2pdfOpts
226− exitWith code
227−
228− let args' = filter (`notElem` markdown2pdfOpts) args
229−
230− -- check for executable files
231− let latexProgram = if "--xetex" `elem` opts
232− then "xelatex"
233− else if "--luatex" `elem` opts
234− then "lualatex"
235− else "pdflatex"
236− let outputFormat = if "--beamer" `elem` opts
237− then "beamer"
238− else "latex"
239− let execs = ["pandoc", latexProgram, "bibtex"]
240− paths <- mapM findExecutable execs
241− let miss = map snd $ filter (isNothing . fst) $ zip paths execs
242− unless (null miss) $ exit $! "Could not find " ++ intercalate ", " miss
243−
244− -- parse arguments
245− -- if no input given, use 'stdin'
246− pandocArgs <- parsePandocArgs args'
247− (input, output) <- case pandocArgs of
248− Nothing -> exit "Could not parse arguments"
249− Just ([],out) -> do
250− stdinFile <- saveStdin (replaceDirectory (takeBaseName out) tmp)
251− case stdinFile of
252− Left err -> exit err
253− Right f -> return ([f], out)
254− -- no need because we'll pass all arguments to pandoc
255− Just (_ ,out) -> return ([], out)
256− -- run pandoc
257− pandocRes <- runPandoc outputFormat (input ++ args') $ replaceDirectory output tmp
258− case pandocRes of
259− Left err -> exit err
260− Right texFile -> do
261− -- run pdflatex
262− latexRes <- runLatex latexProgram texFile
263− case latexRes of
264− Left err -> exit err
265− Right pdfFile -> do
266− -- save the output
267− saveOutput pdfFile $
268− replaceDirectory pdfFile (takeDirectory output)
269−
windows/make-windows-installer.bat−1
@@ -6,7 +6,6 @@ cabal-dev install --flags="executable wrappers -library highlighting" --datasubd
66rem note: we use -f-library in building pandoc, because
77rem if the library is built, the data file paths will not be relocatable!
88strip cabal-dev\bin\pandoc.exe
9−strip cabal-dev\bin\markdown2pdf.exe
109cabal-dev\bin\pandoc.exe -s --template templates\html.template -S README -o README.html
1110copy COPYING COPYING.txt
1211copy COPYRIGHT COPYRIGHT.txt