git.iko.soy/typeable/pandoc
on master help sign in
makePDF: add argument for pdf options, remove writerPdfArgs.
424e94bJohn MacFarlane
src/Text/Pandoc/App.hs+4−3
@@ -449,7 +449,6 @@ convertWithOpts opts = do
449 , writerEpubChapterLevel = optEpubChapterLevel opts
449 , writerEpubChapterLevel = optEpubChapterLevel opts
450 , writerTOCDepth = optTOCDepth opts
450 , writerTOCDepth = optTOCDepth opts
451 , writerReferenceDoc = optReferenceDoc opts
451 , writerReferenceDoc = optReferenceDoc opts
452− , writerPdfArgs = optPdfEngineArgs opts
453 , writerSyntaxMap = syntaxMap
452 , writerSyntaxMap = syntaxMap
454 }
453 }
455
454
@@ -512,14 +511,16 @@ convertWithOpts opts = do
512 ByteStringWriter f -> f writerOptions doc >>= writeFnBinary outputFile
511 ByteStringWriter f -> f writerOptions doc >>= writeFnBinary outputFile
513 TextWriter f -> case maybePdfProg of
512 TextWriter f -> case maybePdfProg of
514 Just pdfProg -> do
513 Just pdfProg -> do
514+ res <- makePDF pdfProg (optPdfEngineArgs opts) f
515− res <- makePDF pdfProg f writerOptions doc
515+ writerOptions doc
516 case res of
516 case res of
517 Right pdf -> writeFnBinary outputFile pdf
517 Right pdf -> writeFnBinary outputFile pdf
518 Left err' -> liftIO $
518 Left err' -> liftIO $
519 E.throwIO $ PandocPDFError (UTF8.toStringLazy err')
519 E.throwIO $ PandocPDFError (UTF8.toStringLazy err')
520 Nothing -> do
520 Nothing -> do
521 let htmlFormat = format `elem`
521 let htmlFormat = format `elem`
522+ ["html","html4","html5","s5","slidy",
522− ["html","html4","html5","s5","slidy","slideous","dzslides","revealjs"]
523+ "slideous","dzslides","revealjs"]
523 handleEntities = if (htmlFormat ||
524 handleEntities = if (htmlFormat ||
524 format == "docbook4" ||
525 format == "docbook4" ||
525 format == "docbook5" ||
526 format == "docbook5" ||
src/Text/Pandoc/Options.hs−2
@@ -221,7 +221,6 @@ data WriterOptions = WriterOptions
221 , writerEpubChapterLevel :: Int -- ^ Header level for chapters (separate files)
221 , writerEpubChapterLevel :: Int -- ^ Header level for chapters (separate files)
222 , writerTOCDepth :: Int -- ^ Number of levels to include in TOC
222 , writerTOCDepth :: Int -- ^ Number of levels to include in TOC
223 , writerReferenceDoc :: Maybe FilePath -- ^ Path to reference document if specified
223 , writerReferenceDoc :: Maybe FilePath -- ^ Path to reference document if specified
224− , writerPdfArgs :: [String] -- ^ Flags to pass to pdf-engine
225 , writerReferenceLocation :: ReferenceLocation -- ^ Location of footnotes and references for writing markdown
224 , writerReferenceLocation :: ReferenceLocation -- ^ Location of footnotes and references for writing markdown
226 , writerSyntaxMap :: SyntaxMap
225 , writerSyntaxMap :: SyntaxMap
227 } deriving (Show, Data, Typeable, Generic)
226 } deriving (Show, Data, Typeable, Generic)
@@ -256,7 +255,6 @@ instance Default WriterOptions where
256 , writerEpubChapterLevel = 1
255 , writerEpubChapterLevel = 1
257 , writerTOCDepth = 3
256 , writerTOCDepth = 3
258 , writerReferenceDoc = Nothing
257 , writerReferenceDoc = Nothing
259− , writerPdfArgs = []
260 , writerReferenceLocation = EndOfDocument
258 , writerReferenceLocation = EndOfDocument
261 , writerSyntaxMap = defaultSyntaxMap
259 , writerSyntaxMap = defaultSyntaxMap
262 }
260 }
src/Text/Pandoc/PDF.hs+11−14
@@ -81,11 +81,12 @@ changePathSeparators = intercalate "/" . splitDirectories
81
81
82makePDF :: String -- ^ pdf creator (pdflatex, lualatex, xelatex,
82makePDF :: String -- ^ pdf creator (pdflatex, lualatex, xelatex,
83 -- wkhtmltopdf, weasyprint, prince, context, pdfroff)
83 -- wkhtmltopdf, weasyprint, prince, context, pdfroff)
84+ -> [String] -- ^ arguments to pass to pdf creator
84 -> (WriterOptions -> Pandoc -> PandocIO Text) -- ^ writer
85 -> (WriterOptions -> Pandoc -> PandocIO Text) -- ^ writer
85 -> WriterOptions -- ^ options
86 -> WriterOptions -- ^ options
86 -> Pandoc -- ^ document
87 -> Pandoc -- ^ document
87 -> PandocIO (Either ByteString ByteString)
88 -> PandocIO (Either ByteString ByteString)
88−makePDF "wkhtmltopdf" writer opts doc@(Pandoc meta _) = do
89+makePDF "wkhtmltopdf" pdfargs writer opts doc@(Pandoc meta _) = do
89 let mathArgs = case writerHTMLMathMethod opts of
90 let mathArgs = case writerHTMLMathMethod opts of
90 -- with MathJax, wait til all math is rendered:
91 -- with MathJax, wait til all math is rendered:
91 MathJax _ -> ["--run-script", "MathJax.Hub.Register.StartupHook('End Typeset', function() { window.status = 'mathjax_loaded' });",
92 MathJax _ -> ["--run-script", "MathJax.Hub.Register.StartupHook('End Typeset', function() { window.status = 'mathjax_loaded' });",
@@ -93,8 +94,7 @@ makePDF "wkhtmltopdf" writer opts doc@(Pandoc meta _) = do
93 _ -> []
94 _ -> []
94 meta' <- metaToJSON opts (return . stringify) (return . stringify) meta
95 meta' <- metaToJSON opts (return . stringify) (return . stringify) meta
95 let toArgs (f, mbd) = maybe [] (\d -> ['-':'-':f, d]) mbd
96 let toArgs (f, mbd) = maybe [] (\d -> ['-':'-':f, d]) mbd
96− let args = writerPdfArgs opts ++ mathArgs ++
97− concatMap toArgs
97+ let args = pdfargs ++ mathArgs ++ concatMap toArgs
98 [("page-size", getField "papersize" meta')
98 [("page-size", getField "papersize" meta')
99 ,("title", getField "title" meta')
99 ,("title", getField "title" meta')
100 ,("margin-bottom", fromMaybe (Just "1.2in")
100 ,("margin-bottom", fromMaybe (Just "1.2in")
@@ -109,23 +109,21 @@ makePDF "wkhtmltopdf" writer opts doc@(Pandoc meta _) = do
109 source <- writer opts doc
109 source <- writer opts doc
110 verbosity <- getVerbosity
110 verbosity <- getVerbosity
111 liftIO $ html2pdf verbosity "wkhtmltopdf" args source
111 liftIO $ html2pdf verbosity "wkhtmltopdf" args source
112−makePDF "weasyprint" writer opts doc = do
112+makePDF "weasyprint" pdfargs writer opts doc = do
113− let args = writerPdfArgs opts
114 source <- writer opts doc
113 source <- writer opts doc
115 verbosity <- getVerbosity
114 verbosity <- getVerbosity
116− liftIO $ html2pdf verbosity "weasyprint" args source
115+ liftIO $ html2pdf verbosity "weasyprint" pdfargs source
117−makePDF "prince" writer opts doc = do
116+makePDF "prince" pdfargs writer opts doc = do
118− let args = writerPdfArgs opts
119 source <- writer opts doc
117 source <- writer opts doc
120 verbosity <- getVerbosity
118 verbosity <- getVerbosity
121− liftIO $ html2pdf verbosity "prince" args source
119+ liftIO $ html2pdf verbosity "prince" pdfargs source
122−makePDF "pdfroff" writer opts doc = do
120+makePDF "pdfroff" pdfargs writer opts doc = do
123 source <- writer opts doc
121 source <- writer opts doc
124 let args = ["-ms", "-mpdfmark", "-e", "-t", "-k", "-KUTF-8", "-i",
122 let args = ["-ms", "-mpdfmark", "-e", "-t", "-k", "-KUTF-8", "-i",
125− "--no-toc-relocation"] ++ writerPdfArgs opts
123+ "--no-toc-relocation"] ++ pdfargs
126 verbosity <- getVerbosity
124 verbosity <- getVerbosity
127 liftIO $ ms2pdf verbosity args source
125 liftIO $ ms2pdf verbosity args source
128−makePDF program writer opts doc = do
126+makePDF program pdfargs writer opts doc = do
129 let withTemp = if takeBaseName program == "context"
127 let withTemp = if takeBaseName program == "context"
130 then withTempDirectory "."
128 then withTempDirectory "."
131 else withTempDir
129 else withTempDir
@@ -136,11 +134,10 @@ makePDF program writer opts doc = do
136 putCommonState commonState
134 putCommonState commonState
137 doc' <- handleImages tmpdir doc
135 doc' <- handleImages tmpdir doc
138 writer opts doc'
136 writer opts doc'
139− let args = writerPdfArgs opts
140 case takeBaseName program of
137 case takeBaseName program of
141 "context" -> context2pdf verbosity tmpdir source
138 "context" -> context2pdf verbosity tmpdir source
142 prog | prog `elem` ["pdflatex", "lualatex", "xelatex"]
139 prog | prog `elem` ["pdflatex", "lualatex", "xelatex"]
143− -> tex2pdf' verbosity args tmpdir program source
140+ -> tex2pdf' verbosity pdfargs tmpdir program source
144 _ -> return $ Left $ UTF8.fromStringLazy $ "Unknown program " ++ program
141 _ -> return $ Left $ UTF8.fromStringLazy $ "Unknown program " ++ program
145
142
146handleImages :: FilePath -- ^ temp dir to store images
143handleImages :: FilePath -- ^ temp dir to store images