@@ -101,6 +101,12 @@ data LuaFilter = LuaFilter LuaState FunctionMap
102newtype LuaFilterFunction = LuaFilterFunction { functionIndex :: Int }
102newtype LuaFilterFunction = LuaFilterFunction { functionIndex :: Int }
104+tryFilter :: StackValue a => LuaState -> FunctionMap -> String -> a -> IO a
105+tryFilter lua fnMap filterFnName x =
106+ case Map.lookup filterFnName fnMap of
108+ Just fn -> runFilterFunction lua fn x
104execDocLuaFilter :: LuaState
110execDocLuaFilter :: LuaState
105 -> FunctionMap
111 -> FunctionMap
106 -> Pandoc -> IO Pandoc
112 -> Pandoc -> IO Pandoc
@@ -116,34 +122,12 @@ execMetaLuaFilter lua fnMap (Pandoc meta blks) = do
116execBlockLuaFilter :: LuaState
122execBlockLuaFilter :: LuaState
117 -> FunctionMap
123 -> FunctionMap
118 -> Block -> IO Block
124 -> Block -> IO Block
119−execBlockLuaFilter lua fnMap x = do
120− tryFilter lua fnMap (show (toConstr x)) x
125+execBlockLuaFilter lua fnMap x = tryFilter lua fnMap (show (toConstr x)) x
122−tryFilter :: StackValue a => LuaState -> FunctionMap -> String -> a -> IO a
123−tryFilter lua fnMap filterFnName x =
124− case Map.lookup filterFnName fnMap of
126− Just fn -> runFilterFunction lua fn x
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
136execInlineLuaFilter :: LuaState
127execInlineLuaFilter :: LuaState
137 -> FunctionMap
128 -> FunctionMap
138 -> Inline -> IO Inline
129 -> Inline -> IO Inline
139−execInlineLuaFilter lua fnMap x = do
140− let tryAlt = tryFilterAlternatives lua fnMap
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
148instance StackValue LuaFilter where
132instance StackValue LuaFilter where
149 valuetype _ = Lua.TTABLE
133 valuetype _ = Lua.TTABLE