summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-06-29 15:47:27 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-06-29 15:47:27 +0200
commit780a65f8a87b40d1a9ee269cd7a51699c42d497e (patch)
tree4f29902be768e6f702226ce7a546748e2391a268 /src/Text/Pandoc/Lua.hs
parent5c80aca0e20492eaa31b9280fb5524d76f5e8098 (diff)
Lua filters: Remove special treatment of Quoted, Math.
No more SingleQuoted, DoubleQuoted, InlineMath, DisplayMath. This makes everything uniform and predictable, though it does open up a difference btw lua filters and custom writers.
Diffstat (limited to 'src/Text/Pandoc/Lua.hs')
-rw-r--r--src/Text/Pandoc/Lua.hs32
1 files changed, 8 insertions, 24 deletions
diff --git a/src/Text/Pandoc/Lua.hs b/src/Text/Pandoc/Lua.hs
index 3bb11b705..fd7bba0ac 100644
--- a/src/Text/Pandoc/Lua.hs
+++ b/src/Text/Pandoc/Lua.hs
@@ -101,6 +101,12 @@ data LuaFilter = LuaFilter LuaState FunctionMap
newtype LuaFilterFunction = LuaFilterFunction { functionIndex :: Int }
+tryFilter :: StackValue a => LuaState -> FunctionMap -> String -> a -> IO a
+tryFilter lua fnMap filterFnName x =
+ case Map.lookup filterFnName fnMap of
+ Nothing -> return x
+ Just fn -> runFilterFunction lua fn x
+
execDocLuaFilter :: LuaState
-> FunctionMap
-> Pandoc -> IO Pandoc
@@ -116,34 +122,12 @@ execMetaLuaFilter lua fnMap (Pandoc meta blks) = do
execBlockLuaFilter :: LuaState
-> FunctionMap
-> Block -> IO Block
-execBlockLuaFilter lua fnMap x = do
- tryFilter lua fnMap (show (toConstr x)) x
-
-tryFilter :: StackValue a => LuaState -> FunctionMap -> String -> a -> IO a
-tryFilter lua fnMap filterFnName x =
- case Map.lookup filterFnName fnMap of
- Nothing -> return x
- Just fn -> runFilterFunction lua fn x
-
-tryFilterAlternatives :: StackValue a
- => LuaState -> FunctionMap -> [String] -> a -> IO a
-tryFilterAlternatives _ _ [] x = return x
-tryFilterAlternatives lua fnMap (fnName : alternatives) x =
- case Map.lookup fnName fnMap of
- Nothing -> tryFilterAlternatives lua fnMap alternatives x
- Just fn -> runFilterFunction lua fn x
+execBlockLuaFilter lua fnMap x = tryFilter lua fnMap (show (toConstr x)) x
execInlineLuaFilter :: LuaState
-> FunctionMap
-> Inline -> IO Inline
-execInlineLuaFilter lua fnMap x = do
- let tryAlt = tryFilterAlternatives lua fnMap
- case x of
- Math DisplayMath _ -> tryAlt ["DisplayMath", "Math"] x
- Math InlineMath _ -> tryAlt ["InlineMath", "Math"] x
- Quoted DoubleQuote _ -> tryAlt ["DoubleQuoted", "Quoted"] x
- Quoted SingleQuote _ -> tryAlt ["SingleQuoted", "Quoted"] x
- _ -> tryFilter lua fnMap (show (toConstr x)) x
+execInlineLuaFilter lua fnMap x = tryFilter lua fnMap (show (toConstr x)) x
instance StackValue LuaFilter where
valuetype _ = Lua.TTABLE