Allow pdf output to stdout.
PDF output will not be output to the terminal, but can be sent to stdout using either `-o -` or a pipe. The intermediate format will be determined based on the setting of `--pdf-engine`. Closes #5751.
This commit is contained in:
parent
c4ff0b5564
commit
e906e5ac23
3 changed files with 19 additions and 14 deletions
|
@ -308,6 +308,7 @@ header when requesting a document from a URL:
|
||||||
- `opml` ([OPML])
|
- `opml` ([OPML])
|
||||||
- `opendocument` ([OpenDocument])
|
- `opendocument` ([OpenDocument])
|
||||||
- `org` ([Emacs Org mode])
|
- `org` ([Emacs Org mode])
|
||||||
|
- `pdf` ([PDF])
|
||||||
- `plain` (plain text),
|
- `plain` (plain text),
|
||||||
- `pptx` ([PowerPoint] slide show)
|
- `pptx` ([PowerPoint] slide show)
|
||||||
- `rst` ([reStructuredText])
|
- `rst` ([reStructuredText])
|
||||||
|
@ -325,7 +326,7 @@ header when requesting a document from a URL:
|
||||||
- the path of a custom lua writer, see [Custom writers] below
|
- the path of a custom lua writer, see [Custom writers] below
|
||||||
:::
|
:::
|
||||||
|
|
||||||
Note that `odt`, `docx`, and `epub` output will not be directed
|
Note that `odt`, `docx`, `epub`, and `pdf` output will not be directed
|
||||||
to *stdout* unless forced with `-o -`.
|
to *stdout* unless forced with `-o -`.
|
||||||
|
|
||||||
Extensions can be individually enabled or
|
Extensions can be individually enabled or
|
||||||
|
|
|
@ -185,7 +185,8 @@ convertWithOpts opts = do
|
||||||
-- force this with '-o -'. On posix systems, we detect
|
-- force this with '-o -'. On posix systems, we detect
|
||||||
-- when stdout is being piped and allow output to stdout
|
-- when stdout is being piped and allow output to stdout
|
||||||
-- in that case, but on Windows we can't.
|
-- in that case, but on Windows we can't.
|
||||||
when (not (isTextFormat format) && istty && isNothing ( optOutputFile opts)) $
|
when ((pdfOutput || not (isTextFormat format)) &&
|
||||||
|
istty && isNothing ( optOutputFile opts)) $
|
||||||
throwError $ PandocAppError $
|
throwError $ PandocAppError $
|
||||||
"Cannot write " ++ format ++ " output to terminal.\n" ++
|
"Cannot write " ++ format ++ " output to terminal.\n" ++
|
||||||
"Specify an output file using the -o option, or " ++
|
"Specify an output file using the -o option, or " ++
|
||||||
|
|
|
@ -65,21 +65,26 @@ optToOutputSettings opts = do
|
||||||
Nothing -> return Nothing
|
Nothing -> return Nothing
|
||||||
Just fp -> Just <$> readUtf8File fp
|
Just fp -> Just <$> readUtf8File fp
|
||||||
|
|
||||||
let pdfOutput = map toLower (takeExtension outputFile) == ".pdf"
|
let pdfOutput = map toLower (takeExtension outputFile) == ".pdf" ||
|
||||||
|
optTo opts == Just "pdf"
|
||||||
(writerName, maybePdfProg) <-
|
(writerName, maybePdfProg) <-
|
||||||
if pdfOutput
|
if pdfOutput
|
||||||
then liftIO $ pdfWriterAndProg (optTo opts) (optPdfEngine opts)
|
then liftIO $ pdfWriterAndProg
|
||||||
|
(case optTo opts of
|
||||||
|
Just "pdf" -> Nothing
|
||||||
|
x -> x)
|
||||||
|
(optPdfEngine opts)
|
||||||
else case optTo opts of
|
else case optTo opts of
|
||||||
|
Just f -> return (f, Nothing)
|
||||||
Nothing
|
Nothing
|
||||||
| outputFile == "-" -> return ("html", Nothing)
|
| outputFile == "-" -> return ("html", Nothing)
|
||||||
| otherwise ->
|
| otherwise ->
|
||||||
case formatFromFilePaths [outputFile] of
|
case formatFromFilePaths [outputFile] of
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
report $ CouldNotDeduceFormat
|
report $ CouldNotDeduceFormat
|
||||||
[takeExtension outputFile] "html"
|
[takeExtension outputFile] "html"
|
||||||
return ("html", Nothing)
|
return ("html", Nothing)
|
||||||
Just f -> return (f, Nothing)
|
Just f -> return (f, Nothing)
|
||||||
Just f -> return (f, Nothing)
|
|
||||||
|
|
||||||
let format = if ".lua" `isSuffixOf` writerName
|
let format = if ".lua" `isSuffixOf` writerName
|
||||||
then writerName
|
then writerName
|
||||||
|
@ -244,13 +249,10 @@ baseWriterName = takeWhile (\c -> c /= '+' && c /= '-')
|
||||||
pdfWriterAndProg :: Maybe String -- ^ user-specified writer name
|
pdfWriterAndProg :: Maybe String -- ^ user-specified writer name
|
||||||
-> Maybe String -- ^ user-specified pdf-engine
|
-> Maybe String -- ^ user-specified pdf-engine
|
||||||
-> IO (String, Maybe String) -- ^ IO (writerName, maybePdfEngineProg)
|
-> IO (String, Maybe String) -- ^ IO (writerName, maybePdfEngineProg)
|
||||||
pdfWriterAndProg mWriter mEngine = do
|
pdfWriterAndProg mWriter mEngine =
|
||||||
let panErr msg = liftIO $ E.throwIO $ PandocAppError msg
|
|
||||||
case go mWriter mEngine of
|
case go mWriter mEngine of
|
||||||
Right (writ, prog) -> return (writ, Just prog)
|
Right (writ, prog) -> return (writ, Just prog)
|
||||||
Left "pdf writer" -> liftIO $ E.throwIO $
|
Left err -> liftIO $ E.throwIO $ PandocAppError err
|
||||||
PandocUnknownWriterError "pdf"
|
|
||||||
Left err -> panErr err
|
|
||||||
where
|
where
|
||||||
go Nothing Nothing = Right ("latex", "pdflatex")
|
go Nothing Nothing = Right ("latex", "pdflatex")
|
||||||
go (Just writer) Nothing = (writer,) <$> engineForWriter writer
|
go (Just writer) Nothing = (writer,) <$> engineForWriter writer
|
||||||
|
@ -273,4 +275,5 @@ pdfWriterAndProg mWriter mEngine = do
|
||||||
"cannot produce pdf output from " ++ w
|
"cannot produce pdf output from " ++ w
|
||||||
|
|
||||||
isTextFormat :: String -> Bool
|
isTextFormat :: String -> Bool
|
||||||
isTextFormat s = s `notElem` ["odt","docx","epub2","epub3","epub","pptx"]
|
isTextFormat s =
|
||||||
|
s `notElem` ["odt","docx","epub2","epub3","epub","pptx","pdf"]
|
||||||
|
|
Loading…
Add table
Reference in a new issue