@@ -34,14 +34,13 @@ import Control.Monad (when)
3434import Data.Default (Default (..))
3535import Data.Maybe (fromMaybe)
3636import Data.Text (pack)
37−import Foreign.Lua (ToLuaStack, FromLuaStack, Lua, NumResults, liftIO)
37+import Foreign.Lua (ToLuaStack, FromLuaStack, Lua, NumResults, Optional, liftIO)
3838import System.Exit (ExitCode (..))
3939import Text.Pandoc.Class (runIO)
4040import Text.Pandoc.Definition (Block, Inline)
4141import Text.Pandoc.Lua.Filter (walkInlines, walkBlocks, LuaFilter)
4242import Text.Pandoc.Lua.StackInstances ()
43−import Text.Pandoc.Lua.Util (OrNil (toMaybe), addFunction, addValue,
44− loadScriptFromDataDir, raiseError)
43+import Text.Pandoc.Lua.Util (addFunction, addValue, loadScriptFromDataDir)
4544import Text.Pandoc.Walk (Walkable)
4645import Text.Pandoc.Options (ReaderOptions (readerExtensions))
4746import Text.Pandoc.Process (pipeProcess)
@@ -72,19 +71,19 @@ walkInline = walkElement
7271walkBlock :: Block -> LuaFilter -> Lua Block
7372walkBlock = walkElement
7473
75−readDoc :: String -> OrNil String -> Lua NumResults
74+readDoc :: String -> Optional String -> Lua NumResults
7675readDoc content formatSpecOrNil = do
77− let formatSpec = fromMaybe "markdown" (toMaybe formatSpecOrNil)
76+ let formatSpec = fromMaybe "markdown" (Lua.fromOptional formatSpecOrNil)
7877 case getReader formatSpec of
79− Left s -> raiseError s -- Unknown reader
78+ Left s -> Lua.raiseError s -- Unknown reader
8079 Right (reader, es) ->
8180 case reader of
8281 TextReader r -> do
8382 res <- liftIO $ runIO $ r def{ readerExtensions = es } (pack content)
8483 case res of
8584 Right pd -> (1 :: NumResults) <$ Lua.push pd -- success, push Pandoc
86− Left s -> raiseError (show s) -- error while reading
87− _ -> raiseError "Only string formats are supported at the moment."
85+ Left s -> Lua.raiseError (show s) -- error while reading
86+ _ -> Lua.raiseError "Only string formats are supported at the moment."
8887
8988-- | Pipes input through a command.
9089pipeFn :: String
@@ -95,7 +94,7 @@ pipeFn command args input = do
9594 (ec, output) <- liftIO $ pipeProcess Nothing command args input
9695 case ec of
9796 ExitSuccess -> 1 <$ Lua.push output
98− ExitFailure n -> raiseError (PipeError command n output)
97+ ExitFailure n -> Lua.raiseError (PipeError command n output)
9998
10099data PipeError = PipeError
101100 { pipeErrorCommand :: String