summaryrefslogtreecommitdiff
path: root/pandoc.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-12-21 17:22:12 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-12-21 17:22:12 -0800
commit0a768f1cc568722973302554265efa414d097da3 (patch)
treed1ed3391ec43848ce1ff163977c4064f5329893c /pandoc.hs
parent32d27896cde18de187be3f8a9e7f9c4ef79b58b3 (diff)
Added preliminary support for PDF creation via wkhtmltopdf.
To use this: pandoc -t html5 -o result.pdf (and add `--mathjax` if you have math.)
Diffstat (limited to 'pandoc.hs')
-rw-r--r--pandoc.hs28
1 files changed, 15 insertions, 13 deletions
diff --git a/pandoc.hs b/pandoc.hs
index cfb9adc1c..a4906382a 100644
--- a/pandoc.hs
+++ b/pandoc.hs
@@ -1168,6 +1168,7 @@ convertWithOpts opts args = do
let laTeXOutput = "latex" `isPrefixOf` writerName' ||
"beamer" `isPrefixOf` writerName'
let conTeXtOutput = "context" `isPrefixOf` writerName'
+ let html5Output = "html5" `isPrefixOf` writerName'
let laTeXInput = "latex" `isPrefixOf` readerName' ||
"beamer" `isPrefixOf` readerName'
@@ -1367,27 +1368,28 @@ convertWithOpts opts args = do
IOByteStringWriter f -> f writerOptions doc' >>= writeBinary
PureStringWriter f
| pdfOutput -> do
- -- make sure writer is latex or beamer
- unless (laTeXOutput || conTeXtOutput) $
+ -- make sure writer is latex or beamer or context or html5
+ unless (laTeXOutput || conTeXtOutput || html5Output) $
err 47 $ "cannot produce pdf output with " ++ writerName' ++
" writer"
- let texprog = if conTeXtOutput
- then "context"
- else latexEngine
- -- check for latex program
- mbLatex <- findExecutable texprog
- when (isNothing mbLatex) $
- err 41 $ texprog ++ " not found. " ++
- texprog ++ " is needed for pdf output."
-
- res <- makePDF texprog f writerOptions doc'
+ let pdfprog = case () of
+ _ | conTeXtOutput -> "context"
+ _ | html5Output -> "wkhtmltopdf"
+ _ -> latexEngine
+ -- check for pdf creating program
+ mbPdfProg <- findExecutable pdfprog
+ when (isNothing mbPdfProg) $
+ err 41 $ pdfprog ++ " not found. " ++
+ pdfprog ++ " is needed for pdf output."
+
+ res <- makePDF pdfprog f writerOptions doc'
case res of
Right pdf -> writeBinary pdf
Left err' -> do
B.hPutStr stderr err'
B.hPut stderr $ B.pack [10]
- err 43 "Error producing PDF from TeX source"
+ err 43 "Error producing PDF"
| otherwise -> selfcontain (f writerOptions doc' ++
['\n' | not standalone'])
>>= writerFn outputFile . handleEntities