diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2023-03-26 10:24:52 -0700 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2023-03-26 10:25:07 -0700 |
| commit | 2a1d5c49d0b978b631e367737acdee81cdfe9cd3 (patch) | |
| tree | 0bb8f3f8c8df8fdd8663a91ba751a538ee9f8120 /src/Text | |
| parent | 2821ca72ff7149fa6797fce7b5e5c9323b530fc8 (diff) | |
Support typst as a pdf-engine.
Diffstat (limited to 'src/Text')
| -rw-r--r-- | src/Text/Pandoc/App/CommandLineOptions.hs | 1 | ||||
| -rw-r--r-- | src/Text/Pandoc/PDF.hs | 34 |
2 files changed, 20 insertions, 15 deletions
diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs index 1d3b76cc7..8c96be58d 100644 --- a/src/Text/Pandoc/App/CommandLineOptions.hs +++ b/src/Text/Pandoc/App/CommandLineOptions.hs @@ -223,6 +223,7 @@ engines = map ("html",) htmlEngines ++ map ("latex",) latexEngines ++ map ("beamer",) latexEngines ++ [ ("ms", "pdfroff") + , ("typst", "typst") , ("context", "context") ] diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs index c769efa4d..476b74d76 100644 --- a/src/Text/Pandoc/PDF.hs +++ b/src/Text/Pandoc/PDF.hs @@ -85,9 +85,17 @@ makePDF program pdfargs writer opts doc = case takeBaseName program of "wkhtmltopdf" -> makeWithWkhtmltopdf program pdfargs writer opts doc prog | prog `elem` ["pagedjs-cli" ,"weasyprint", "prince"] -> do + let mkOutArgs f = + if program `elem` ["pagedjs-cli", "prince"] + then ["-o", f] + else [f] source <- writer opts doc verbosity <- getVerbosity - liftIO $ html2pdf verbosity program pdfargs source + liftIO $ toPdfViaTempFile verbosity program pdfargs mkOutArgs source + "typst" -> do + source <- writer opts doc + verbosity <- getVerbosity + liftIO $ toPdfViaTempFile verbosity program pdfargs (:[]) source "pdfroff" -> do source <- writer opts doc let paperargs = @@ -174,7 +182,7 @@ makeWithWkhtmltopdf program pdfargs writer opts doc@(Pandoc meta _) = do -- see #6474 source <- writer opts doc verbosity <- getVerbosity - liftIO $ html2pdf verbosity program args source + liftIO $ toPdfViaTempFile verbosity program args (:[]) source handleImages :: (PandocMonad m, MonadIO m) => WriterOptions @@ -432,24 +440,20 @@ generic2pdf program args source = do ExitFailure _ -> Left out ExitSuccess -> Right out - -html2pdf :: Verbosity -- ^ Verbosity level - -> String -- ^ Program (wkhtmltopdf, weasyprint, prince, or path) +toPdfViaTempFile :: + Verbosity -- ^ Verbosity level + -> String -- ^ Program (program name or path) -> [String] -- ^ Args to program - -> Text -- ^ HTML5 source + -> (String -> [String]) -- ^ Construct args for output file + -> Text -- ^ Source -> IO (Either ByteString ByteString) -html2pdf verbosity program args source = - -- write HTML to temp file so we don't have to rewrite - -- all links in `a`, `img`, `style`, `script`, etc. tags, - -- and piping to weasyprint didn't work on Windows either. - withTempFile "." "html2pdf.html" $ \file h1 -> - withTempFile "." "html2pdf.pdf" $ \pdfFile h2 -> do +toPdfViaTempFile verbosity program args mkOutArgs source = + withTempFile "." "toPdfViaTempFile.html" $ \file h1 -> + withTempFile "." "toPdfViaTempFile.pdf" $ \pdfFile h2 -> do hClose h1 hClose h2 BS.writeFile file $ UTF8.fromText source - let pdfFileArgName = ["-o" | takeBaseName program `elem` - ["pagedjs-cli", "prince"]] - let programArgs = args ++ [file] ++ pdfFileArgName ++ [pdfFile] + let programArgs = args ++ [file] ++ mkOutArgs pdfFile env' <- getEnvironment when (verbosity >= INFO) $ UTF8.readFile file >>= |
