git.iko.soy/typeable/pandoc
on master help sign in
Custom writer: remove old preprocesesor conditionals
5cb18e5Albert Krewinkel
src/Text/Pandoc/Writers/Custom.hs−36
@@ -60,7 +60,6 @@ attrToMap (id',classes,keyvals) = M.fromList
60 : ("class", unwords classes)
60 : ("class", unwords classes)
61 : keyvals
61 : keyvals
62
62
63−#if MIN_VERSION_hslua(0,4,0)
64#if MIN_VERSION_base(4,8,0)
63#if MIN_VERSION_base(4,8,0)
65instance {-# OVERLAPS #-} StackValue [Char] where
64instance {-# OVERLAPS #-} StackValue [Char] where
66#else
65#else
@@ -71,37 +70,6 @@ instance StackValue [Char] where
71 res <- Lua.peek lua i
70 res <- Lua.peek lua i
72 return $ UTF8.toString `fmap` res
71 return $ UTF8.toString `fmap` res
73 valuetype _ = Lua.TSTRING
72 valuetype _ = Lua.TSTRING
74−#else
75−#if MIN_VERSION_base(4,8,0)
76−instance {-# OVERLAPS #-} StackValue a => StackValue [a] where
77−#else
78−instance StackValue a => StackValue [a] where
79−#endif
80− push lua xs = do
81− Lua.createtable lua (length xs + 1) 0
82− let addValue (i, x) = Lua.push lua x >> Lua.rawseti lua (-2) i
83− mapM_ addValue $ zip [1..] xs
84− peek lua i = do
85− top <- Lua.gettop lua
86− let i' = if i < 0 then top + i + 1 else i
87− Lua.pushnil lua
88− lst <- getList lua i'
89− Lua.pop lua 1
90− return (Just lst)
91− valuetype _ = Lua.TTABLE
92−
93−getList :: StackValue a => LuaState -> Int -> IO [a]
94−getList lua i' = do
95− continue <- Lua.next lua i'
96− if continue
97− then do
98− next <- Lua.peek lua (-1)
99− Lua.pop lua 1
100− x <- maybe (fail "peek returned Nothing") return next
101− rest <- getList lua i'
102− return (x : rest)
103− else return []
104−#endif
105
73
106instance StackValue Format where
74instance StackValue Format where
107 push lua (Format f) = Lua.push lua (map toLower f)
75 push lua (Format f) = Lua.push lua (map toLower f)
@@ -191,11 +159,7 @@ writeCustom luaFile opts doc@(Pandoc meta _) = do
191 -- check for error in lua script (later we'll change the return type
159 -- check for error in lua script (later we'll change the return type
192 -- to handle this more gracefully):
160 -- to handle this more gracefully):
193 when (status /= 0) $
161 when (status /= 0) $
194−#if MIN_VERSION_hslua(0,4,0)
195 Lua.tostring lua 1 >>= throw . PandocLuaException . UTF8.toString
162 Lua.tostring lua 1 >>= throw . PandocLuaException . UTF8.toString
196−#else
197− Lua.tostring lua 1 >>= throw . PandocLuaException
198−#endif
199 Lua.call lua 0 0
163 Lua.call lua 0 0
200 -- TODO - call hierarchicalize, so we have that info
164 -- TODO - call hierarchicalize, so we have that info
201 rendered <- docToCustom lua opts doc
165 rendered <- docToCustom lua opts doc