aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2020-03-25 22:16:27 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2020-04-17 21:52:48 +0200
commitfb54f3d6792d2f8e7b05e458b59142f8ae6bb3e2 (patch)
treeb5403849735559bd28050fe8bccf068bdf37f48a /src/Text/Pandoc/Writers
parent2877ca70ecaf5b6715b38f41165974f89206d18b (diff)
downloadpandoc-fb54f3d6792d2f8e7b05e458b59142f8ae6bb3e2.tar.gz
API change: use PandocError for exceptions in Lua subsystem
The PandocError type is used throughout the Lua subsystem, all Lua functions throw an exception of this type if an error occurs. The `LuaException` type is removed and no longer exported from `Text.Pandoc.Lua`. In its place, a new constructor `PandocLuaError` is added to PandocError.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/Custom.hs27
1 files changed, 9 insertions, 18 deletions
diff --git a/src/Text/Pandoc/Writers/Custom.hs b/src/Text/Pandoc/Writers/Custom.hs
index 2be64d56f..50a013dfd 100644
--- a/src/Text/Pandoc/Writers/Custom.hs
+++ b/src/Text/Pandoc/Writers/Custom.hs
@@ -20,17 +20,14 @@ import Data.List (intersperse)
import qualified Data.Map as M
import qualified Data.Text as T
import Data.Text (Text, pack)
-import Data.Typeable
import Foreign.Lua (Lua, Pushable)
import Text.DocLayout (render, literal)
import Text.Pandoc.Class.PandocIO (PandocIO)
import Text.Pandoc.Definition
-import Text.Pandoc.Lua (Global (..), LuaException (LuaException),
- runLua, setGlobals)
+import Text.Pandoc.Lua (Global (..), runLua, setGlobals)
import Text.Pandoc.Lua.Util (addField, dofileWithTraceback)
import Text.Pandoc.Options
import Text.Pandoc.Templates (renderTemplate)
-import qualified Text.Pandoc.UTF8 as UTF8
import Text.Pandoc.Writers.Shared
import qualified Foreign.Lua as Lua
@@ -81,11 +78,6 @@ instance (Pushable a, Pushable b) => Pushable (KeyValue a b) where
Lua.push v
Lua.rawset (Lua.nthFromTop 3)
-data PandocLuaException = PandocLuaException Text
- deriving (Show, Typeable)
-
-instance Exception PandocLuaException
-
-- | Convert Pandoc to custom markup.
writeCustom :: FilePath -> WriterOptions -> Pandoc -> PandocIO Text
writeCustom luaFile opts doc@(Pandoc meta _) = do
@@ -97,21 +89,20 @@ writeCustom luaFile opts doc@(Pandoc meta _) = do
stat <- dofileWithTraceback luaFile
-- check for error in lua script (later we'll change the return type
-- to handle this more gracefully):
- when (stat /= Lua.OK) $
- Lua.tostring' (-1) >>= throw . PandocLuaException . UTF8.toText
+ when (stat /= Lua.OK)
+ Lua.throwTopMessage
rendered <- docToCustom opts doc
context <- metaToContext opts
(fmap (literal . pack) . blockListToCustom)
(fmap (literal . pack) . inlineListToCustom)
meta
return (pack rendered, context)
- let (body, context) = case res of
- Left (LuaException msg) -> throw (PandocLuaException msg)
- Right x -> x
- return $
- case writerTemplate opts of
- Nothing -> body
- Just tpl -> render Nothing $
+ case res of
+ Left msg -> throw msg
+ Right (body, context) -> return $
+ case writerTemplate opts of
+ Nothing -> body
+ Just tpl -> render Nothing $
renderTemplate tpl $ setField "body" body context
docToCustom :: WriterOptions -> Pandoc -> Lua String