git.iko.soy/typeable/pandoc
on master help sign in
makePDF: add argument for pdf options, remove writerPdfArgs.

- Removed writerPdfArgs from WriterOptions (API change). - Added parameter for pdf args to makePDF.

commit424e94bd4509715cfc2dd62efadfd842e06fd472 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 26 Oct 2017, 11:11 (9 years ago) parent456148f
3 files changed+15−19
src/Text/Pandoc/App.hs+4−3 src/Text/Pandoc/Options.hs−2 src/Text/Pandoc/PDF.hs+11−14
src/Text/Pandoc/App.hs+4−3
@@ -449,7 +449,6 @@ convertWithOpts opts = do
449449 , writerEpubChapterLevel = optEpubChapterLevel opts
450450 , writerTOCDepth = optTOCDepth opts
451451 , writerReferenceDoc = optReferenceDoc opts
452− , writerPdfArgs = optPdfEngineArgs opts
453452 , writerSyntaxMap = syntaxMap
454453 }
455454
@@ -512,14 +511,16 @@ convertWithOpts opts = do
512511 ByteStringWriter f -> f writerOptions doc >>= writeFnBinary outputFile
513512 TextWriter f -> case maybePdfProg of
514513 Just pdfProg -> do
515− res <- makePDF pdfProg f writerOptions doc
514+ res <- makePDF pdfProg (optPdfEngineArgs opts) f
515+ writerOptions doc
516516 case res of
517517 Right pdf -> writeFnBinary outputFile pdf
518518 Left err' -> liftIO $
519519 E.throwIO $ PandocPDFError (UTF8.toStringLazy err')
520520 Nothing -> do
521521 let htmlFormat = format `elem`
522− ["html","html4","html5","s5","slidy","slideous","dzslides","revealjs"]
522+ ["html","html4","html5","s5","slidy",
523+ "slideous","dzslides","revealjs"]
523524 handleEntities = if (htmlFormat ||
524525 format == "docbook4" ||
525526 format == "docbook5" ||
src/Text/Pandoc/Options.hs−2
@@ -221,7 +221,6 @@ data WriterOptions = WriterOptions
221221 , writerEpubChapterLevel :: Int -- ^ Header level for chapters (separate files)
222222 , writerTOCDepth :: Int -- ^ Number of levels to include in TOC
223223 , writerReferenceDoc :: Maybe FilePath -- ^ Path to reference document if specified
224− , writerPdfArgs :: [String] -- ^ Flags to pass to pdf-engine
225224 , writerReferenceLocation :: ReferenceLocation -- ^ Location of footnotes and references for writing markdown
226225 , writerSyntaxMap :: SyntaxMap
227226 } deriving (Show, Data, Typeable, Generic)
@@ -256,7 +255,6 @@ instance Default WriterOptions where
256255 , writerEpubChapterLevel = 1
257256 , writerTOCDepth = 3
258257 , writerReferenceDoc = Nothing
259− , writerPdfArgs = []
260258 , writerReferenceLocation = EndOfDocument
261259 , writerSyntaxMap = defaultSyntaxMap
262260 }
src/Text/Pandoc/PDF.hs+11−14
@@ -81,11 +81,12 @@ changePathSeparators = intercalate "/" . splitDirectories
8181
8282makePDF :: String -- ^ pdf creator (pdflatex, lualatex, xelatex,
8383 -- wkhtmltopdf, weasyprint, prince, context, pdfroff)
84+ -> [String] -- ^ arguments to pass to pdf creator
8485 -> (WriterOptions -> Pandoc -> PandocIO Text) -- ^ writer
8586 -> WriterOptions -- ^ options
8687 -> Pandoc -- ^ document
8788 -> PandocIO (Either ByteString ByteString)
88−makePDF "wkhtmltopdf" writer opts doc@(Pandoc meta _) = do
89+makePDF "wkhtmltopdf" pdfargs writer opts doc@(Pandoc meta _) = do
8990 let mathArgs = case writerHTMLMathMethod opts of
9091 -- with MathJax, wait til all math is rendered:
9192 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
9394 _ -> []
9495 meta' <- metaToJSON opts (return . stringify) (return . stringify) meta
9596 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
9898 [("page-size", getField "papersize" meta')
9999 ,("title", getField "title" meta')
100100 ,("margin-bottom", fromMaybe (Just "1.2in")
@@ -109,23 +109,21 @@ makePDF "wkhtmltopdf" writer opts doc@(Pandoc meta _) = do
109109 source <- writer opts doc
110110 verbosity <- getVerbosity
111111 liftIO $ html2pdf verbosity "wkhtmltopdf" args source
112−makePDF "weasyprint" writer opts doc = do
113− let args = writerPdfArgs opts
112+makePDF "weasyprint" pdfargs writer opts doc = do
114113 source <- writer opts doc
115114 verbosity <- getVerbosity
116− liftIO $ html2pdf verbosity "weasyprint" args source
117−makePDF "prince" writer opts doc = do
118− let args = writerPdfArgs opts
115+ liftIO $ html2pdf verbosity "weasyprint" pdfargs source
116+makePDF "prince" pdfargs writer opts doc = do
119117 source <- writer opts doc
120118 verbosity <- getVerbosity
121− liftIO $ html2pdf verbosity "prince" args source
122−makePDF "pdfroff" writer opts doc = do
119+ liftIO $ html2pdf verbosity "prince" pdfargs source
120+makePDF "pdfroff" pdfargs writer opts doc = do
123121 source <- writer opts doc
124122 let args = ["-ms", "-mpdfmark", "-e", "-t", "-k", "-KUTF-8", "-i",
125− "--no-toc-relocation"] ++ writerPdfArgs opts
123+ "--no-toc-relocation"] ++ pdfargs
126124 verbosity <- getVerbosity
127125 liftIO $ ms2pdf verbosity args source
128−makePDF program writer opts doc = do
126+makePDF program pdfargs writer opts doc = do
129127 let withTemp = if takeBaseName program == "context"
130128 then withTempDirectory "."
131129 else withTempDir
@@ -136,11 +134,10 @@ makePDF program writer opts doc = do
136134 putCommonState commonState
137135 doc' <- handleImages tmpdir doc
138136 writer opts doc'
139− let args = writerPdfArgs opts
140137 case takeBaseName program of
141138 "context" -> context2pdf verbosity tmpdir source
142139 prog | prog `elem` ["pdflatex", "lualatex", "xelatex"]
143− -> tex2pdf' verbosity args tmpdir program source
140+ -> tex2pdf' verbosity pdfargs tmpdir program source
144141 _ -> return $ Left $ UTF8.fromStringLazy $ "Unknown program " ++ program
145142
146143handleImages :: FilePath -- ^ temp dir to store images