diff options
| author | John MacFarlane <[email protected]> | 2022-11-09 17:36:23 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-12-20 20:58:44 -0800 |
| commit | 063480accd3421bfc77478b8dbddc1985553ed75 (patch) | |
| tree | 4ef6d846f17085cbc2f7410123d7698c4196b069 /src/Text/Pandoc/Scripting.hs | |
| parent | 8553459f61eb2290008fafedcfbb1df0bb1fe1b4 (diff) | |
T.P.Scripting: Refactor the scripting engine.
The new type CustomComponents is exported from T.P.Scripting, and the
ScriptEngine fields are changed. Instead of separate fields for custom
readers and writers, we now have a single function that loads any number
of "components" from a script: these may be custom readers, custom
writers, templates for writers, or extension configs. (Note: it's
possible to have a custom reader and a custom writer for a format
together in the same file.)
Pandoc now checks the folder `custom` in the user's data directory for a
matching script if it can't find one in the local directory. Previously,
the `readers` and `writers` data directories were search for custom
readers and writers, respectively. Scripts in those directories must be
moved to the `custom` folder.
Custom readers used to implement a fallback behavior that allowed to
consume just a string value as input to the `Reader` function. This has
been removed, the first argument is now always a list of sources. Use
`tostring` on that argument to get a string.
Closes #8417.
Signed-off-by: Albert Krewinkel <[email protected]>
Diffstat (limited to 'src/Text/Pandoc/Scripting.hs')
| -rw-r--r-- | src/Text/Pandoc/Scripting.hs | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/Text/Pandoc/Scripting.hs b/src/Text/Pandoc/Scripting.hs index 1942014cb..8b90a9749 100644 --- a/src/Text/Pandoc/Scripting.hs +++ b/src/Text/Pandoc/Scripting.hs @@ -11,6 +11,7 @@ Central data structure for scripting engines. -} module Text.Pandoc.Scripting ( ScriptingEngine (..) + , CustomComponents(..) , noEngine ) where @@ -26,6 +27,18 @@ import Text.Pandoc.Format (ExtensionsConfig) import Text.Pandoc.Readers (Reader) import Text.Pandoc.Writers (Writer) +-- | A component of a custom reader/writer: a custom reader, +-- a custom writer, a template for a custom writer, or a specification +-- of the extensions used by a script and their default values. +-- Note that a single script can contain all of these. +data CustomComponents m = + CustomComponents + { customReader :: Maybe (Reader m) + , customWriter :: Maybe (Writer m) + , customTemplate :: Maybe Text + , customExtensions :: Maybe ExtensionsConfig + } + -- | Structure to define a scripting engine. data ScriptingEngine = ScriptingEngine { engineName :: Text -- ^ Name of the engine. @@ -35,14 +48,9 @@ data ScriptingEngine = ScriptingEngine -> Pandoc -> m Pandoc -- ^ Use the scripting engine to run a filter. - , engineReadCustom :: forall m. (PandocMonad m, MonadIO m) - => FilePath -> m (Reader m, ExtensionsConfig) - -- ^ Function to parse input into a 'Pandoc' document. - - , engineWriteCustom :: forall m. (PandocMonad m, MonadIO m) - => FilePath - -> m (Writer m, ExtensionsConfig, Maybe Text) - -- ^ Invoke the given script file to convert to any custom format. + , engineLoadCustom :: forall m. (PandocMonad m, MonadIO m) + => FilePath -> m (CustomComponents m) + -- ^ Function to load a custom reader/writer from a script. } noEngine :: ScriptingEngine @@ -50,8 +58,6 @@ noEngine = ScriptingEngine { engineName = "none" , engineApplyFilter = \_env _args _fp _doc -> throwError PandocNoScriptingEngine - , engineReadCustom = \_fp -> - throwError PandocNoScriptingEngine - , engineWriteCustom = \_fp -> + , engineLoadCustom = \_fp -> throwError PandocNoScriptingEngine } |
