summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2017-04-14 11:21:58 +0200
committerAlbert Krewinkel <albert@zeitkraut.de>2017-04-14 11:34:44 +0200
commit07f41a5515c0d753c8b3fa074132ba219db8360c (patch)
tree54a2fdea10ea81694357d1f6a7884431490b287b /src
parent0516b5127c3674786f92c61f4131428ed3b8bd4b (diff)
Lua filter: use destructured functions for block filters
Filtering functions take element components as arguments instead of the whole block elements. This resembles the way elements are handled in custom writers.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Lua.hs40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/Text/Pandoc/Lua.hs b/src/Text/Pandoc/Lua.hs
index bca6a2589..9903d4df6 100644
--- a/src/Text/Pandoc/Lua.hs
+++ b/src/Text/Pandoc/Lua.hs
@@ -107,24 +107,30 @@ execBlockLuaFilter :: LuaState
-> Map String (LuaFilterFunction Block)
-> Block -> IO Block
execBlockLuaFilter lua fnMap x = do
- let filterOrId constr = case Map.lookup constr fnMap of
- Nothing -> return x
- Just fn -> runLuaFilterFunction lua fn x
+ let runFn :: PushViaFilterFunction Block a => LuaFilterFunction Block -> a
+ runFn fn = runLuaFilterFunction lua fn
+ let tryFilter :: String -> (LuaFilterFunction Block -> IO Block) -> IO Block
+ tryFilter fnName callFilterFn =
+ case Map.lookup fnName fnMap of
+ Nothing -> return x
+ Just fn -> callFilterFn fn
case x of
- Plain _ -> filterOrId "Plain"
- Para _ -> filterOrId "Para"
- LineBlock _ -> filterOrId "LineBlock"
- CodeBlock _ _ -> filterOrId "CodeBlock"
- RawBlock _ _ -> filterOrId "RawBlock"
- BlockQuote _ -> filterOrId "BlockQuote"
- OrderedList _ _ -> filterOrId "OrderedList"
- BulletList _ -> filterOrId "BulletList"
- DefinitionList _ -> filterOrId "DefinitionList"
- Header _ _ _ -> filterOrId "Header"
- HorizontalRule -> filterOrId "HorizontalRule"
- Table _ _ _ _ _ -> filterOrId "Table"
- Div _ _ -> filterOrId "Div"
- Null -> filterOrId "Null"
+ HorizontalRule -> tryFilter "HorizontalRule" runFn
+ Null -> tryFilter "Null" runFn
+ BlockQuote blcks -> tryFilter "BlockQuote" $ \fn -> runFn fn blcks
+ BulletList items -> tryFilter "BulletList" $ \fn -> runFn fn items
+ CodeBlock attr code -> tryFilter "CodeBlock" $ \fn -> runFn fn attr code
+ DefinitionList lst -> tryFilter "DefinitionList" $ \fn -> runFn fn lst
+ Div attr content -> tryFilter "Div" $ \fn -> runFn fn content attr
+ Header lvl attr inlns -> tryFilter "Header" $ \fn -> runFn fn lvl inlns attr
+ LineBlock inlns -> tryFilter "LineBlock" $ \fn -> runFn fn inlns
+ Para inlns -> tryFilter "Para" $ \fn -> runFn fn inlns
+ Plain inlns -> tryFilter "Plain" $ \fn -> runFn fn inlns
+ RawBlock format str -> tryFilter "RawBlock" $ \fn -> runFn fn format str
+ OrderedList (num,sty,delim) items ->
+ tryFilter "OrderedList" $ \fn -> runFn fn items (num,sty,delim)
+ Table capt aligns widths headers rows ->
+ tryFilter "Table" $ \fn -> runFn fn capt aligns widths headers rows
execInlineLuaFilter :: LuaState
-> Map String (LuaFilterFunction Inline)