aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-07-07 20:27:24 -0400
committerJohn MacFarlane <[email protected]>2025-07-07 20:27:24 -0400
commitca2c82133f09c3093be2c8014378ddc15f899a0d (patch)
treeb8c79242b83cb391b903aaf56f6d60f69829d437 /src
parent55f0f88d83aca1314a3bb253af4f8a965eb38cfe (diff)
PDF: make images from MediaBag available in tmp dir...
for every PDF engine, not just LaTeX/ConTeXt. This is part of the fix for #10911.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/PDF.hs60
1 files changed, 26 insertions, 34 deletions
diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs
index e3157ce96..22757f103 100644
--- a/src/Text/Pandoc/PDF.hs
+++ b/src/Text/Pandoc/PDF.hs
@@ -81,7 +81,19 @@ makePDF :: (PandocMonad m, MonadIO m, MonadMask m)
-> WriterOptions -- ^ options
-> Pandoc -- ^ document
-> m (Either ByteString ByteString)
-makePDF program pdfargs writer opts doc =
+makePDF program pdfargs writer opts doc = withTempDir (program == "typst") "media" $ \mediaDir -> do
+#ifdef _WINDOWS
+ -- note: we want / even on Windows, for TexLive
+ let tmpdir = changePathSeparators mediaDir
+#else
+ let tmpdir = mediaDir
+#endif
+ doc' <- handleImages opts tmpdir doc
+ source <- writer opts{ writerExtensions = -- disable use of quote
+ -- ligatures to avoid bad ligatures like ?`
+ disableExtension Ext_smart
+ (writerExtensions opts) } doc'
+ verbosity <- getVerbosity
case takeBaseName program of
"wkhtmltopdf" -> makeWithWkhtmltopdf program pdfargs writer opts doc
prog | prog `elem` ["pagedjs-cli" ,"weasyprint", "prince"] -> do
@@ -89,16 +101,10 @@ makePDF program pdfargs writer opts doc =
if program `elem` ["pagedjs-cli", "prince"]
then ["-o", f]
else [f]
- source <- writer opts doc
- verbosity <- getVerbosity
liftIO $ toPdfViaTempFile verbosity program pdfargs mkOutArgs ".html" source
- "typst" -> do
- source <- writer opts doc
- verbosity <- getVerbosity
- liftIO $
+ "typst" -> liftIO $
toPdfViaTempFile verbosity program ("compile":pdfargs) (:[]) ".typ" source
"pdfroff" -> do
- source <- writer opts doc
let paperargs =
case lookupContext "papersize" (writerVariables opts) of
Just s
@@ -112,7 +118,6 @@ makePDF program pdfargs writer opts doc =
paperargs ++ pdfargs
generic2pdf program args source
"groff" -> do
- source <- writer opts doc
let paperargs =
case lookupContext "papersize" (writerVariables opts) of
Just s
@@ -125,33 +130,20 @@ makePDF program pdfargs writer opts doc =
["-U" | ".PDFPIC" `T.isInfixOf` source] ++
paperargs ++ pdfargs
generic2pdf program args source
- baseProg -> do
- withTempDir "tex2pdf." $ \tmpdir' -> do
-#ifdef _WINDOWS
- -- note: we want / even on Windows, for TexLive
- let tmpdir = changePathSeparators tmpdir'
-#else
- let tmpdir = tmpdir'
-#endif
- doc' <- handleImages opts tmpdir doc
- source <- writer opts{ writerExtensions = -- disable use of quote
- -- ligatures to avoid bad ligatures like ?`
- disableExtension Ext_smart
- (writerExtensions opts) } doc'
- case baseProg of
- "context" -> context2pdf program pdfargs tmpdir source
- "tectonic" -> tectonic2pdf program pdfargs tmpdir source
- prog | prog `elem` ["pdflatex", "lualatex", "xelatex", "latexmk"]
- -> tex2pdf program pdfargs tmpdir source
- _ -> return $ Left $ UTF8.fromStringLazy
- $ "Unknown program " ++ program
+ baseProg ->
+ case baseProg of
+ "context" -> context2pdf program pdfargs tmpdir source
+ "tectonic" -> tectonic2pdf program pdfargs tmpdir source
+ prog | prog `elem` ["pdflatex", "lualatex", "xelatex", "latexmk"]
+ -> tex2pdf program pdfargs tmpdir source
+ _ -> return $ Left $ UTF8.fromStringLazy $ "Unknown program " ++ program
-- latex has trouble with tildes in paths, which
-- you find in Windows temp dir paths with longer
-- user names (see #777)
withTempDir :: (PandocMonad m, MonadMask m, MonadIO m)
- => FilePath -> (FilePath -> m a) -> m a
-withTempDir templ action = do
+ => Bool -> FilePath -> (FilePath -> m a) -> m a
+withTempDir useWorkingDirectory templ action = do
tmp <- liftIO getTemporaryDirectory
uname <- liftIO $ E.catch
(do (ec, sout, _) <- readProcessWithExitCode "uname" ["-o"] ""
@@ -159,9 +151,9 @@ withTempDir templ action = do
then return $ Just $ filter (not . isSpace) sout
else return Nothing)
(\(_ :: E.SomeException) -> return Nothing)
- if '~' `elem` tmp || uname == Just "Cygwin" -- see #5451
- then withTempDirectory "." templ action
- else withSystemTempDirectory templ action
+ if useWorkingDirectory || '~' `elem` tmp || uname == Just "Cygwin" -- see #5451
+ then withTempDirectory "." templ action
+ else withSystemTempDirectory templ action
makeWithWkhtmltopdf :: (PandocMonad m, MonadIO m)
=> String -- ^ wkhtmltopdf or path