From a088cbf5637596a461ba9f99b49210235d6c0a68 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Fri, 7 Oct 2022 21:37:57 +0200 Subject: Lua: support extensions in custom writers Custom writers can define the extensions that they support via the global `writer_extensions`. The variable's value must be a table with all supported extensions as keys, and their default status as values. E.g., the below specifies that the writer support the extensions `smart` and `sourcepos`, but only the `smart` extension is enabled by default: writer_extensions = { smart = true, sourcepos = false, } --- src/Text/Pandoc/App/OutputSettings.hs | 4 +++- src/Text/Pandoc/Scripting.hs | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/App/OutputSettings.hs b/src/Text/Pandoc/App/OutputSettings.hs index 20321f52a..ab224cd7f 100644 --- a/src/Text/Pandoc/App/OutputSettings.hs +++ b/src/Text/Pandoc/App/OutputSettings.hs @@ -107,7 +107,9 @@ optToOutputSettings scriptingEngine opts = do (writer, writerExts) <- if "lua" `T.isSuffixOf` format then do - (, mempty) <$> engineWriteCustom scriptingEngine (T.unpack format) + (w, extsConf) <- engineWriteCustom scriptingEngine (T.unpack format) + wexts <- Format.applyExtensionsDiff extsConf flvrd + return (w, wexts) else do if optSandbox opts then case runPure (getWriter flvrd) of diff --git a/src/Text/Pandoc/Scripting.hs b/src/Text/Pandoc/Scripting.hs index 09b19f12e..0defa2f77 100644 --- a/src/Text/Pandoc/Scripting.hs +++ b/src/Text/Pandoc/Scripting.hs @@ -18,10 +18,11 @@ where import Control.Monad.Except (throwError) import Control.Monad.IO.Class (MonadIO) import Data.Text (Text) -import Text.Pandoc.Definition (Pandoc) import Text.Pandoc.Class.PandocMonad (PandocMonad) +import Text.Pandoc.Definition (Pandoc) import Text.Pandoc.Error (PandocError (PandocNoScriptingEngine)) import Text.Pandoc.Filter.Environment (Environment) +import Text.Pandoc.Format (ExtensionsConfig) import Text.Pandoc.Readers (Reader) import Text.Pandoc.Writers (Writer) @@ -39,7 +40,7 @@ data ScriptingEngine = ScriptingEngine -- ^ Function to parse input into a 'Pandoc' document. , engineWriteCustom :: forall m. (PandocMonad m, MonadIO m) - => FilePath -> m (Writer m) + => FilePath -> m (Writer m, ExtensionsConfig) -- ^ Invoke the given script file to convert to any custom format. } -- cgit v1.2.3