@@ -31,10 +31,9 @@ import Control.Monad (unless)
3131import Data.ByteString.Char8 (unpack)
3232import Data.Default (Default (..))
3333import Data.Text (pack)
34−import Foreign.Lua (Lua, Status (OK), liftIO, push, pushHaskellFunction)
35−import Foreign.Lua.Api (call, loadstring, rawset)
36−import Text.Pandoc.Class
37−import Text.Pandoc.Definition (Pandoc)
34+import Foreign.Lua (Lua, Status (OK), NumResults, call, loadstring, liftIO,
35+ push, pushHaskellFunction, rawset)
36+import Text.Pandoc.Class (readDataFile, runIO, runIOorExplode, setUserDataDir)
3837import Text.Pandoc.Options (ReaderOptions(readerExtensions))
3938import Text.Pandoc.Lua.StackInstances ()
4039import Text.Pandoc.Readers (Reader (..), getReader)
@@ -54,16 +53,17 @@ pandocModuleScript :: Maybe FilePath -> IO String
5453pandocModuleScript datadir = unpack <$>
5554 runIOorExplode (setUserDataDir datadir >> readDataFile "pandoc.lua")
5655
57−readDoc :: String -> String -> Lua (Either String Pandoc)
58−readDoc formatSpec content = liftIO $ do
56+readDoc :: String -> String -> Lua NumResults
57+readDoc formatSpec content = do
5958 case getReader formatSpec of
60− Left s -> return $ Left s
59+ Left s -> push s -- Unknown reader
6160 Right (reader, es) ->
6261 case reader of
6362 TextReader r -> do
64− res <- runIO $ r def{ readerExtensions = es } (pack content)
63+ res <- liftIO $ runIO $ r def{ readerExtensions = es } (pack content)
6564 case res of
66− Left s -> return . Left $ show s
67− Right pd -> return $ Right pd
68− _ -> return $ Left "Only string formats are supported at the moment."
65+ Left s -> push $ show s -- error while reading
66+ Right pd -> push pd -- success, push Pandoc
67+ _ -> push "Only string formats are supported at the moment."
68+ return 1
6969