@@ -101,6 +101,12 @@ data LuaFilter = LuaFilter LuaState FunctionMap
101101
102102newtype LuaFilterFunction = LuaFilterFunction { functionIndex :: Int }
103103
104+tryFilter :: StackValue a => LuaState -> FunctionMap -> String -> a -> IO a
105+tryFilter lua fnMap filterFnName x =
106+ case Map.lookup filterFnName fnMap of
107+ Nothing -> return x
108+ Just fn -> runFilterFunction lua fn x
109+
104110execDocLuaFilter :: LuaState
105111 -> FunctionMap
106112 -> Pandoc -> IO Pandoc
@@ -116,34 +122,12 @@ execMetaLuaFilter lua fnMap (Pandoc meta blks) = do
116122execBlockLuaFilter :: LuaState
117123 -> FunctionMap
118124 -> Block -> IO Block
119−execBlockLuaFilter lua fnMap x = do
120− tryFilter lua fnMap (show (toConstr x)) x
121−
122−tryFilter :: StackValue a => LuaState -> FunctionMap -> String -> a -> IO a
123−tryFilter lua fnMap filterFnName x =
124− case Map.lookup filterFnName fnMap of
125− Nothing -> return x
126− Just fn -> runFilterFunction lua fn x
127−
128−tryFilterAlternatives :: StackValue a
129− => LuaState -> FunctionMap -> [String] -> a -> IO a
130−tryFilterAlternatives _ _ [] x = return x
131−tryFilterAlternatives lua fnMap (fnName : alternatives) x =
132− case Map.lookup fnName fnMap of
133− Nothing -> tryFilterAlternatives lua fnMap alternatives x
134− Just fn -> runFilterFunction lua fn x
125+execBlockLuaFilter lua fnMap x = tryFilter lua fnMap (show (toConstr x)) x
135126
136127execInlineLuaFilter :: LuaState
137128 -> FunctionMap
138129 -> Inline -> IO Inline
139−execInlineLuaFilter lua fnMap x = do
140− let tryAlt = tryFilterAlternatives lua fnMap
141− case x of
142− Math DisplayMath _ -> tryAlt ["DisplayMath", "Math"] x
143− Math InlineMath _ -> tryAlt ["InlineMath", "Math"] x
144− Quoted DoubleQuote _ -> tryAlt ["DoubleQuoted", "Quoted"] x
145− Quoted SingleQuote _ -> tryAlt ["SingleQuoted", "Quoted"] x
146− _ -> tryFilter lua fnMap (show (toConstr x)) x
130+execInlineLuaFilter lua fnMap x = tryFilter lua fnMap (show (toConstr x)) x
147131
148132instance StackValue LuaFilter where
149133 valuetype _ = Lua.TTABLE