summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers/Custom.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-06-20 22:43:48 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-06-20 22:43:48 +0200
commitc349f0b0baef5866041b6668fff5bbb16f0002f9 (patch)
tree09f8bf2c95b3e66c1eff98ef9756c6503a2032b8 /src/Text/Pandoc/Writers/Custom.hs
parent21c4281b13bf2d72012139ecc5c16cf7cae21de1 (diff)
Writers: adjusted for renderTemplate' changes.
Now we raise a proper error on template failure.
Diffstat (limited to 'src/Text/Pandoc/Writers/Custom.hs')
-rw-r--r--src/Text/Pandoc/Writers/Custom.hs7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/Custom.hs b/src/Text/Pandoc/Writers/Custom.hs
index 1314ef844..363bad99b 100644
--- a/src/Text/Pandoc/Writers/Custom.hs
+++ b/src/Text/Pandoc/Writers/Custom.hs
@@ -46,6 +46,7 @@ import Data.Typeable
import GHC.IO.Encoding (getForeignEncoding, setForeignEncoding, utf8)
import Scripting.Lua (LuaState, StackValue, callfunc)
import qualified Scripting.Lua as Lua
+import Text.Pandoc.Error
import Text.Pandoc.Lua.Compat ( loadstring )
import Text.Pandoc.Lua.Util ( addValue )
import Text.Pandoc.Lua.SharedInstances ()
@@ -141,8 +142,10 @@ writeCustom luaFile opts doc@(Pandoc meta _) = do
let body = rendered
case writerTemplate opts of
Nothing -> return $ pack body
- Just tpl -> return $ pack $
- renderTemplate' tpl $ setField "body" body context
+ Just tpl ->
+ case applyTemplate (pack tpl) $ setField "body" body context of
+ Left e -> throw (PandocTemplateError e)
+ Right r -> return (pack r)
docToCustom :: LuaState -> WriterOptions -> Pandoc -> IO String
docToCustom lua opts (Pandoc (Meta metamap) blocks) = do