@@ -58,7 +58,6 @@ import System.IO.Error (isDoesNotExistError)
59import Text.Pandoc.Definition
59import Text.Pandoc.Definition
60import Text.Pandoc.Error (PandocError(PandocPDFProgramNotFoundError))
60import Text.Pandoc.Error (PandocError(PandocPDFProgramNotFoundError))
61−import Text.Pandoc.MediaBag
62import Text.Pandoc.MIME (getMimeType)
61import Text.Pandoc.MIME (getMimeType)
63import Text.Pandoc.Options (HTMLMathMethod (..), WriterOptions (..))
62import Text.Pandoc.Options (HTMLMathMethod (..), WriterOptions (..))
64import Text.Pandoc.Process (pipeProcess)
63import Text.Pandoc.Process (pipeProcess)
@@ -70,8 +69,9 @@ import Text.Pandoc.Writers.Shared (getField, metaToJSON)
70import Data.List (intercalate)
69import Data.List (intercalate)
72import Text.Pandoc.Class (PandocIO, report, runIO, runIOorExplode,
71import Text.Pandoc.Class (PandocIO, report, runIO, runIOorExplode,
73− setMediaBag, setVerbosity, getResourcePath,
72+ setVerbosity, getVerbosity,
74− setResourcePath, fillMediaBag, extractMedia)
73+ fillMediaBag, extractMedia, putCommonState,
75import Text.Pandoc.Logging
75import Text.Pandoc.Logging
77#ifdef _WINDOWS
77#ifdef _WINDOWS
@@ -83,11 +83,9 @@ makePDF :: String -- ^ pdf creator (pdflatex, lualatex, xelatex,
83 -- wkhtmltopdf, weasyprint, prince, context, pdfroff)
83 -- wkhtmltopdf, weasyprint, prince, context, pdfroff)
84 -> (WriterOptions -> Pandoc -> PandocIO Text) -- ^ writer
84 -> (WriterOptions -> Pandoc -> PandocIO Text) -- ^ writer
85 -> WriterOptions -- ^ options
85 -> WriterOptions -- ^ options
86− -> Verbosity -- ^ verbosity level
87− -> MediaBag -- ^ media
88 -> Pandoc -- ^ document
86 -> Pandoc -- ^ document
89 -> PandocIO (Either ByteString ByteString)
87 -> PandocIO (Either ByteString ByteString)
90−makePDF "wkhtmltopdf" writer opts verbosity _ doc@(Pandoc meta _) = do
88+makePDF "wkhtmltopdf" writer opts doc@(Pandoc meta _) = do
91 let mathArgs = case writerHTMLMathMethod opts of
89 let mathArgs = case writerHTMLMathMethod opts of
92 -- with MathJax, wait til all math is rendered:
90 -- with MathJax, wait til all math is rendered:
93 MathJax _ -> ["--run-script", "MathJax.Hub.Register.StartupHook('End Typeset', function() { window.status = 'mathjax_loaded' });",
91 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
109 (getField "margin-left" meta'))
107 (getField "margin-left" meta'))
111 source <- writer opts doc
109 source <- writer opts doc
110+ verbosity <- getVerbosity
112 liftIO $ html2pdf verbosity "wkhtmltopdf" args source
111 liftIO $ html2pdf verbosity "wkhtmltopdf" args source
113−makePDF "weasyprint" writer opts verbosity _ doc = do
112+makePDF "weasyprint" writer opts doc = do
114 let args = writerPdfArgs opts
113 let args = writerPdfArgs opts
115 source <- writer opts doc
114 source <- writer opts doc
115+ verbosity <- getVerbosity
116 liftIO $ html2pdf verbosity "weasyprint" args source
116 liftIO $ html2pdf verbosity "weasyprint" args source
117−makePDF "prince" writer opts verbosity _ doc = do
117+makePDF "prince" writer opts doc = do
118 let args = writerPdfArgs opts
118 let args = writerPdfArgs opts
119 source <- writer opts doc
119 source <- writer opts doc
120+ verbosity <- getVerbosity
120 liftIO $ html2pdf verbosity "prince" args source
121 liftIO $ html2pdf verbosity "prince" args source
121−makePDF "pdfroff" writer opts verbosity _mediabag doc = do
122+makePDF "pdfroff" writer opts doc = do
122 source <- writer opts doc
123 source <- writer opts doc
123 let args = ["-ms", "-mpdfmark", "-e", "-t", "-k", "-KUTF-8", "-i",
124 let args = ["-ms", "-mpdfmark", "-e", "-t", "-k", "-KUTF-8", "-i",
124 "--no-toc-relocation"] ++ writerPdfArgs opts
125 "--no-toc-relocation"] ++ writerPdfArgs opts
126+ verbosity <- getVerbosity
125 liftIO $ ms2pdf verbosity args source
127 liftIO $ ms2pdf verbosity args source
126−makePDF program writer opts verbosity mediabag doc = do
128+makePDF program writer opts doc = do
127 let withTemp = if takeBaseName program == "context"
129 let withTemp = if takeBaseName program == "context"
128 then withTempDirectory "."
130 then withTempDirectory "."
129 else withTempDir
131 else withTempDir
130− resourcePath <- getResourcePath
132+ commonState <- getCommonState
133+ verbosity <- getVerbosity
131 liftIO $ withTemp "tex2pdf." $ \tmpdir -> do
134 liftIO $ withTemp "tex2pdf." $ \tmpdir -> do
132− doc' <- handleImages verbosity resourcePath mediabag tmpdir doc
133 source <- runIOorExplode $ do
135 source <- runIOorExplode $ do
134− setVerbosity verbosity
136+ putCommonState commonState
137+ doc' <- handleImages tmpdir doc
135 writer opts doc'
138 writer opts doc'
136 let args = writerPdfArgs opts
139 let args = writerPdfArgs opts
137 case takeBaseName program of
140 case takeBaseName program of
@@ -140,34 +143,25 @@ makePDF program writer opts verbosity mediabag doc = do
140 -> tex2pdf' verbosity args tmpdir program source
143 -> tex2pdf' verbosity args tmpdir program source
141 _ -> return $ Left $ UTF8.fromStringLazy $ "Unknown program " ++ program
144 _ -> return $ Left $ UTF8.fromStringLazy $ "Unknown program " ++ program
143−handleImages :: Verbosity
146− -> FilePath -- ^ temp dir to store images
146+handleImages :: FilePath -- ^ temp dir to store images
147 -> Pandoc -- ^ document
147 -> Pandoc -- ^ document
148− -> IO Pandoc
148+ -> PandocIO Pandoc
149−handleImages verbosity resourcePath mediabag tmpdir doc = do
149+handleImages tmpdir doc =
150− doc' <- runIOorExplode $ do
151− setVerbosity verbosity
152− setResourcePath resourcePath
153− setMediaBag mediabag
154− fillMediaBag doc >>=
150+ fillMediaBag doc >>=
155− extractMedia tmpdir
151+ extractMedia tmpdir >>=
156− walkM (convertImages verbosity tmpdir) doc'
152+ walkM (convertImages tmpdir)
158−convertImages :: Verbosity -> FilePath -> Inline -> IO Inline
154+convertImages :: FilePath -> Inline -> PandocIO Inline
159−convertImages verbosity tmpdir (Image attr ils (src, tit)) = do
155+convertImages tmpdir (Image attr ils (src, tit)) = do
160− img <- convertImage tmpdir src
156+ img <- liftIO $ convertImage tmpdir src
161 newPath <-
157 newPath <-
162 case img of
158 case img of
163 Left e -> do
159 Left e -> do
165− setVerbosity verbosity
166− report $ CouldNotConvertImage src e
160+ report $ CouldNotConvertImage src e
167 return src
161 return src
168 Right fp -> return fp
162 Right fp -> return fp
169 return (Image attr ils (newPath, tit))
163 return (Image attr ils (newPath, tit))
170−convertImages _ _ x = return x
164+convertImages _ x = return x
172-- Convert formats which do not work well in pdf to png
166-- Convert formats which do not work well in pdf to png
173convertImage :: FilePath -> FilePath -> IO (Either String FilePath)
167convertImage :: FilePath -> FilePath -> IO (Either String FilePath)