@@ -1,5 +1,5 @@
1{-# LANGUAGE OverlappingInstances, FlexibleInstances, OverloadedStrings,
1{-# LANGUAGE OverlappingInstances, FlexibleInstances, OverloadedStrings,
2− ScopedTypeVariables #-}
2+ ScopedTypeVariables, DeriveDataTypeable #-}
3{-# OPTIONS_GHC -fno-warn-orphans #-}
3{-# OPTIONS_GHC -fno-warn-orphans #-}
4{- Copyright (C) 2012-2014 John MacFarlane <jgm@berkeley.edu>
4{- Copyright (C) 2012-2014 John MacFarlane <jgm@berkeley.edu>
@@ -35,6 +35,7 @@ import Text.Pandoc.Definition
35import Text.Pandoc.Options
35import Text.Pandoc.Options
36import Data.List ( intersperse )
36import Data.List ( intersperse )
37import Data.Char ( toLower )
37import Data.Char ( toLower )
38import Scripting.Lua (LuaState, StackValue, callfunc)
39import Scripting.Lua (LuaState, StackValue, callfunc)
39import Text.Pandoc.Writers.Shared
40import Text.Pandoc.Writers.Shared
40import qualified Scripting.Lua as Lua
41import qualified Scripting.Lua as Lua
@@ -43,6 +44,7 @@ import Data.ByteString (ByteString)
43import qualified Data.ByteString.Char8 as C8
44import qualified Data.ByteString.Char8 as C8
44import Data.Monoid
45import Data.Monoid
45import Control.Monad (when)
46import Control.Monad (when)
47+import Control.Exception
46import qualified Data.Map as M
48import qualified Data.Map as M
47import Text.Pandoc.Templates
49import Text.Pandoc.Templates
@@ -146,6 +148,11 @@ instance StackValue Citation where
146 peek = undefined
148 peek = undefined
147 valuetype _ = Lua.TTABLE
149 valuetype _ = Lua.TTABLE
151+data PandocLuaException = PandocLuaException String
152+ deriving (Show, Typeable)
154+instance Exception PandocLuaException
149-- | Convert Pandoc to custom markup.
156-- | Convert Pandoc to custom markup.
150writeCustom :: FilePath -> WriterOptions -> Pandoc -> IO String
157writeCustom :: FilePath -> WriterOptions -> Pandoc -> IO String
151writeCustom luaFile opts doc@(Pandoc meta _) = do
158writeCustom luaFile opts doc@(Pandoc meta _) = do
@@ -156,7 +163,7 @@ writeCustom luaFile opts doc@(Pandoc meta _) = do
156 -- check for error in lua script (later we'll change the return type
163 -- check for error in lua script (later we'll change the return type
157 -- to handle this more gracefully):
164 -- to handle this more gracefully):
158 when (status /= 0) $
165 when (status /= 0) $
159− Lua.tostring lua 1 >>= error
166+ Lua.tostring lua 1 >>= throw . PandocLuaException
160 Lua.call lua 0 0
167 Lua.call lua 0 0
161 -- TODO - call hierarchicalize, so we have that info
168 -- TODO - call hierarchicalize, so we have that info
162 rendered <- docToCustom lua opts doc
169 rendered <- docToCustom lua opts doc