diff options
| author | Albert Krewinkel <albert@zeitkraut.de> | 2022-12-04 23:16:01 +0100 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2022-12-05 08:52:37 -0800 |
| commit | a03b77fbd35a0547f51429cd24388728aadd2008 (patch) | |
| tree | 52d64efed811804febc2b6352e80887e9ded6792 /src/Text/Pandoc/App/CommandLineOptions.hs | |
| parent | a4ac1ebb954b0eaf0eac0805b8340b1609ef5d8f (diff) | |
Lua: support `-D` CLI option for custom writers [API change]
A new error `PandocNoTemplateError` (code 87) is thrown if a template is
required but cannot be found.
Diffstat (limited to 'src/Text/Pandoc/App/CommandLineOptions.hs')
| -rw-r--r-- | src/Text/Pandoc/App/CommandLineOptions.hs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs index 78f548fb3..a65fe5a04 100644 --- a/src/Text/Pandoc/App/CommandLineOptions.hs +++ b/src/Text/Pandoc/App/CommandLineOptions.hs @@ -51,6 +51,7 @@ import Text.Pandoc.App.Opt (Opt (..), LineEnding (..), IpynbOutput (..), fullDefaultsPath, OptInfo(..)) import Text.Pandoc.Filter (Filter (..)) import Text.Pandoc.Highlighting (highlightingStyles, lookupHighlightingStyle) +import Text.Pandoc.Scripting (ScriptingEngine (..)) import Text.Pandoc.Shared (safeStrRead) import Text.Printf import qualified Control.Exception as E @@ -60,7 +61,6 @@ import qualified Data.ByteString.Lazy as B import qualified Data.Map as M import qualified Data.Text as T import qualified Text.Pandoc.UTF8 as UTF8 -import Text.Pandoc.Scripting (ScriptingEngine(..)) parseOptions :: [OptDescr (Opt -> ExceptT OptInfo IO Opt)] -> Opt -> IO (Either OptInfo Opt) @@ -105,7 +105,7 @@ parseOptionsFromArgs options' defaults prg rawArgs = do -- | React to an 'OptInfo' by printing the requested information -- and exiting or (if there was a parsing error) raising an error. handleOptInfo :: ScriptingEngine -> OptInfo -> IO () -handleOptInfo _engine info = E.handle (handleError . Left) $ do +handleOptInfo engine info = E.handle (handleError . Left) $ do case info of BashCompletion -> do datafiles <- getDataFileNames @@ -152,9 +152,19 @@ handleOptInfo _engine info = E.handle (handleError . Left) $ do mapM_ (UTF8.hPutStrLn stdout . fst) highlightingStyles PrintDefaultTemplate mbout fmt -> do let write = maybe (UTF8.hPutStr stdout) (UTF8.writeFile) mbout - templ <- runIO $ do - setUserDataDir Nothing - getDefaultTemplate fmt + + templ <- runIO $ + case splitExtension (T.unpack fmt) of + (_, "") -> do + -- built-in format + setUserDataDir Nothing + getDefaultTemplate fmt + _ -> do + -- format looks like a filepath => custom writer + (_, _, mt) <- engineWriteCustom engine (T.unpack fmt) + case mt of + Just t -> pure t + Nothing -> E.throw $ PandocNoTemplateError fmt case templ of Right t | T.null t -> -- e.g. for docx, odt, json: |
