{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ImpredicativeTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Text.Pandoc.Scripting
( ScriptingEngine (..)
, CustomComponents(..)
, noEngine
)
where
import Control.Monad.Except (throwError)
import Control.Monad.IO.Class (MonadIO)
import Data.Text (Text)
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)
data CustomComponents m =
CustomComponents
{ forall (m :: * -> *). CustomComponents m -> Maybe (Reader m)
customReader :: Maybe (Reader m)
, forall (m :: * -> *). CustomComponents m -> Maybe (Writer m)
customWriter :: Maybe (Writer m)
, forall (m :: * -> *). CustomComponents m -> Maybe Text
customTemplate :: Maybe Text
, forall (m :: * -> *). CustomComponents m -> Maybe ExtensionsConfig
customExtensions :: Maybe ExtensionsConfig
}
data ScriptingEngine = ScriptingEngine
{ ScriptingEngine -> Text
engineName :: Text
, ScriptingEngine
-> forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
Environment -> [String] -> String -> Pandoc -> m Pandoc
engineApplyFilter :: forall m. (PandocMonad m, MonadIO m)
=> Environment -> [String] -> FilePath
-> Pandoc -> m Pandoc
, ScriptingEngine
-> forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
String -> m (CustomComponents m)
engineLoadCustom :: forall m. (PandocMonad m, MonadIO m)
=> FilePath -> m (CustomComponents m)
}
noEngine :: ScriptingEngine
noEngine :: ScriptingEngine
noEngine = ScriptingEngine
{ engineName :: Text
engineName = Text
"none"
, engineApplyFilter :: forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
Environment -> [String] -> String -> Pandoc -> m Pandoc
engineApplyFilter = \Environment
_env [String]
_args String
_fp Pandoc
_doc ->
PandocError -> m Pandoc
forall a. PandocError -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError PandocError
PandocNoScriptingEngine
, engineLoadCustom :: forall (m :: * -> *).
(PandocMonad m, MonadIO m) =>
String -> m (CustomComponents m)
engineLoadCustom = \String
_fp ->
PandocError -> m (CustomComponents m)
forall a. PandocError -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError PandocError
PandocNoScriptingEngine
}