git.iko.soy/typeable/pandoc
on master help sign in
Removed Verbosity and MediaBag params from makePDF.

They can be obtained from CommonState since we're in PandocIO.

commitdfe816163c3122cff03e2d7d7b286a60916587fb authorJohn MacFarlane <jgm@berkeley.edu> dateSat 30 Sep 2017, 17:17 (9 years ago) parent9ec458f
2 files changed+29−36
src/Text/Pandoc/App.hs+2−3 src/Text/Pandoc/PDF.hs+27−33
src/Text/Pandoc/App.hs+2−3
@@ -76,7 +76,7 @@ import qualified System.IO as IO (Newline (..))
7676import Text.Pandoc
7777import Text.Pandoc.Builder (setMeta)
7878import Text.Pandoc.Class (PandocIO, extractMedia, fillMediaBag, getLog,
79− setResourcePath, getMediaBag, setTrace, report,
79+ setResourcePath, setTrace, report,
8080 setUserDataDir, readFileStrict, readDataFile,
8181 readDefaultDataFile, setTranslations,
8282 setInputFiles, setOutputFile)
@@ -509,13 +509,12 @@ convertWithOpts opts = do
509509 >=> applyTransforms transforms
510510 >=> applyFilters readerOpts datadir filters' [format]
511511 )
512− media <- getMediaBag
513512
514513 case writer of
515514 ByteStringWriter f -> f writerOptions doc >>= writeFnBinary outputFile
516515 TextWriter f -> case maybePdfProg of
517516 Just pdfProg -> do
518− res <- makePDF pdfProg f writerOptions verbosity media doc
517+ res <- makePDF pdfProg f writerOptions doc
519518 case res of
520519 Right pdf -> writeFnBinary outputFile pdf
521520 Left err' -> liftIO $
src/Text/Pandoc/PDF.hs+27−33
@@ -58,7 +58,6 @@ import System.IO.Error (isDoesNotExistError)
5858#endif
5959import Text.Pandoc.Definition
6060import Text.Pandoc.Error (PandocError(PandocPDFProgramNotFoundError))
61−import Text.Pandoc.MediaBag
6261import Text.Pandoc.MIME (getMimeType)
6362import Text.Pandoc.Options (HTMLMathMethod (..), WriterOptions (..))
6463import Text.Pandoc.Process (pipeProcess)
@@ -70,8 +69,9 @@ import Text.Pandoc.Writers.Shared (getField, metaToJSON)
7069import Data.List (intercalate)
7170#endif
7271import Text.Pandoc.Class (PandocIO, report, runIO, runIOorExplode,
73− setMediaBag, setVerbosity, getResourcePath,
74− setResourcePath, fillMediaBag, extractMedia)
72+ setVerbosity, getVerbosity,
73+ fillMediaBag, extractMedia, putCommonState,
74+ getCommonState)
7575import Text.Pandoc.Logging
7676
7777#ifdef _WINDOWS
@@ -83,11 +83,9 @@ makePDF :: String -- ^ pdf creator (pdflatex, lualatex, xelatex,
8383 -- wkhtmltopdf, weasyprint, prince, context, pdfroff)
8484 -> (WriterOptions -> Pandoc -> PandocIO Text) -- ^ writer
8585 -> WriterOptions -- ^ options
86− -> Verbosity -- ^ verbosity level
87− -> MediaBag -- ^ media
8886 -> Pandoc -- ^ document
8987 -> PandocIO (Either ByteString ByteString)
90−makePDF "wkhtmltopdf" writer opts verbosity _ doc@(Pandoc meta _) = do
88+makePDF "wkhtmltopdf" writer opts doc@(Pandoc meta _) = do
9189 let mathArgs = case writerHTMLMathMethod opts of
9290 -- with MathJax, wait til all math is rendered:
9391 MathJax _ -> ["--run-script", "MathJax.Hub.Register.StartupHook('End Typeset', function() { window.status = 'mathjax_loaded' });",
@@ -109,29 +107,34 @@ makePDF "wkhtmltopdf" writer opts verbosity _ doc@(Pandoc meta _) = do
109107 (getField "margin-left" meta'))
110108 ]
111109 source <- writer opts doc
110+ verbosity <- getVerbosity
112111 liftIO $ html2pdf verbosity "wkhtmltopdf" args source
113−makePDF "weasyprint" writer opts verbosity _ doc = do
112+makePDF "weasyprint" writer opts doc = do
114113 let args = writerPdfArgs opts
115114 source <- writer opts doc
115+ verbosity <- getVerbosity
116116 liftIO $ html2pdf verbosity "weasyprint" args source
117−makePDF "prince" writer opts verbosity _ doc = do
117+makePDF "prince" writer opts doc = do
118118 let args = writerPdfArgs opts
119119 source <- writer opts doc
120+ verbosity <- getVerbosity
120121 liftIO $ html2pdf verbosity "prince" args source
121−makePDF "pdfroff" writer opts verbosity _mediabag doc = do
122+makePDF "pdfroff" writer opts doc = do
122123 source <- writer opts doc
123124 let args = ["-ms", "-mpdfmark", "-e", "-t", "-k", "-KUTF-8", "-i",
124125 "--no-toc-relocation"] ++ writerPdfArgs opts
126+ verbosity <- getVerbosity
125127 liftIO $ ms2pdf verbosity args source
126−makePDF program writer opts verbosity mediabag doc = do
128+makePDF program writer opts doc = do
127129 let withTemp = if takeBaseName program == "context"
128130 then withTempDirectory "."
129131 else withTempDir
130− resourcePath <- getResourcePath
132+ commonState <- getCommonState
133+ verbosity <- getVerbosity
131134 liftIO $ withTemp "tex2pdf." $ \tmpdir -> do
132− doc' <- handleImages verbosity resourcePath mediabag tmpdir doc
133135 source <- runIOorExplode $ do
134− setVerbosity verbosity
136+ putCommonState commonState
137+ doc' <- handleImages tmpdir doc
135138 writer opts doc'
136139 let args = writerPdfArgs opts
137140 case takeBaseName program of
@@ -140,34 +143,25 @@ makePDF program writer opts verbosity mediabag doc = do
140143 -> tex2pdf' verbosity args tmpdir program source
141144 _ -> return $ Left $ UTF8.fromStringLazy $ "Unknown program " ++ program
142145
143−handleImages :: Verbosity
144− -> [FilePath]
145− -> MediaBag
146− -> FilePath -- ^ temp dir to store images
146+handleImages :: FilePath -- ^ temp dir to store images
147147 -> Pandoc -- ^ document
148− -> IO Pandoc
149−handleImages verbosity resourcePath mediabag tmpdir doc = do
150− doc' <- runIOorExplode $ do
151− setVerbosity verbosity
152− setResourcePath resourcePath
153− setMediaBag mediabag
154− fillMediaBag doc >>=
155− extractMedia tmpdir
156− walkM (convertImages verbosity tmpdir) doc'
148+ -> PandocIO Pandoc
149+handleImages tmpdir doc =
150+ fillMediaBag doc >>=
151+ extractMedia tmpdir >>=
152+ walkM (convertImages tmpdir)
157153
158−convertImages :: Verbosity -> FilePath -> Inline -> IO Inline
159−convertImages verbosity tmpdir (Image attr ils (src, tit)) = do
160− img <- convertImage tmpdir src
154+convertImages :: FilePath -> Inline -> PandocIO Inline
155+convertImages tmpdir (Image attr ils (src, tit)) = do
156+ img <- liftIO $ convertImage tmpdir src
161157 newPath <-
162158 case img of
163159 Left e -> do
164− runIO $ do
165− setVerbosity verbosity
166− report $ CouldNotConvertImage src e
160+ report $ CouldNotConvertImage src e
167161 return src
168162 Right fp -> return fp
169163 return (Image attr ils (newPath, tit))
170−convertImages _ _ x = return x
164+convertImages _ x = return x
171165
172166-- Convert formats which do not work well in pdf to png
173167convertImage :: FilePath -> FilePath -> IO (Either String FilePath)