From 7dc59aa26ae368e885d6c1070c8c576030b705d1 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Wed, 9 Feb 2022 19:16:41 +0100 Subject: [PATCH] PDF: allow custom writer as format if engine is explicitly specified (#7901) Closes #7898. Note that it may be necessary to explicitly specify a template on the command line. --- src/Text/Pandoc/App/OutputSettings.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Text/Pandoc/App/OutputSettings.hs b/src/Text/Pandoc/App/OutputSettings.hs index 5af0baccd..988f2def5 100644 --- a/src/Text/Pandoc/App/OutputSettings.hs +++ b/src/Text/Pandoc/App/OutputSettings.hs @@ -254,6 +254,10 @@ pdfWriterAndProg mWriter mEngine = go Nothing Nothing = Right ("latex", "pdflatex") go (Just writer) Nothing = (writer,) <$> engineForWriter writer go Nothing (Just engine) = (,engine) <$> writerForEngine (takeBaseName engine) + go (Just writer) (Just engine) | isCustomWriter writer = + -- custom writers can produce any format, so assume the user knows + -- what they are doing. + Right (writer, engine) go (Just writer) (Just engine) = case find (== (baseWriterName writer, takeBaseName engine)) engines of Just _ -> Right (writer, engine) @@ -266,11 +270,13 @@ pdfWriterAndProg mWriter mEngine = "pdf-engine " <> T.pack eng <> " not known" engineForWriter "pdf" = Left "pdf writer" - engineForWriter w = case [e | (f,e) <- engines, f == baseWriterName w] of + engineForWriter w = case [e | (f,e) <- engines, f == baseWriterName w] of eng : _ -> Right eng [] -> Left $ "cannot produce pdf output from " <> w + isCustomWriter w = ".lua" `T.isSuffixOf` w + isTextFormat :: T.Text -> Bool isTextFormat s = s `notElem` ["odt","docx","epub2","epub3","epub","pptx","pdf"]