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 | |
| parent | 2821ca72ff7149fa6797fce7b5e5c9323b530fc8 (diff) | |
Support typst as a pdf-engine.
| -rw-r--r-- | MANUAL.txt | 3 | ||||
| -rw-r--r-- | src/Text/Pandoc/App/CommandLineOptions.hs | 1 | ||||
| -rw-r--r-- | src/Text/Pandoc/PDF.hs | 34 |
3 files changed, 22 insertions, 16 deletions
diff --git a/MANUAL.txt b/MANUAL.txt index 147c8e4e2..47624d502 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -1369,7 +1369,7 @@ header when requesting a document from a URL: : Use the specified engine when producing PDF output. Valid values are `pdflatex`, `lualatex`, `xelatex`, `latexmk`, `tectonic`, `wkhtmltopdf`, `weasyprint`, `pagedjs-cli`, - `prince`, `context`, and `pdfroff`. If the engine is not in + `prince`, `context`, `pdfroff`, and `typst`. If the engine is not in your PATH, the full path of the engine may be specified here. If this option is not specified, pandoc uses the following defaults depending on the output format specified using @@ -1383,6 +1383,7 @@ header when requesting a document from a URL: see [print-css.rocks](https://print-css.rocks) for a good introduction to PDF generation from HTML/CSS) - `-t ms`: `pdfroff` + - `-t typst`: `typst` `--pdf-engine-opt=`*STRING* 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 >>= |
