aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2017-04-16 21:06:50 +0200
committerAlbert Krewinkel <albert+github@zeitkraut.de>2017-04-26 23:28:40 +0200
commit9cd20c9b8b1fa3bd4581399327d61551558cf899 (patch)
treefc9c8769f453139f6d4286d84f1bb9fa7906d5b4
parent5416fb14aba9804ce4a227a4ebd8228d82aa658e (diff)
downloadpandoc-9cd20c9b8b1fa3bd4581399327d61551558cf899.tar.gz
Lua filter: allow filtering of meta data only
-rw-r--r--src/Text/Pandoc/Lua.hs14
-rw-r--r--test/lua/smallcaps-title.lua12
2 files changed, 25 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Lua.hs b/src/Text/Pandoc/Lua.hs
index 0d1c6cf45..ffc57c9c2 100644
--- a/src/Text/Pandoc/Lua.hs
+++ b/src/Text/Pandoc/Lua.hs
@@ -75,7 +75,8 @@ runAll (x:xs) = walkMWithLuaFilter x >=> runAll xs
walkMWithLuaFilter :: LuaFilter -> Pandoc -> IO Pandoc
walkMWithLuaFilter (LuaFilter lua fnMap) =
walkM (execInlineLuaFilter lua fnMap) >=>
- walkM (execBlockLuaFilter lua fnMap) >=>
+ walkM (execBlockLuaFilter lua fnMap) >=>
+ walkM (execMetaLuaFilter lua fnMap) >=>
walkM (execDocLuaFilter lua fnMap)
type FunctionMap = Map String LuaFilterFunction
@@ -92,6 +93,17 @@ execDocLuaFilter lua fnMap x = do
Nothing -> return x
Just fn -> runLuaFilterFunction lua fn x
+execMetaLuaFilter :: LuaState
+ -> FunctionMap
+ -> Pandoc -> IO Pandoc
+execMetaLuaFilter lua fnMap pd@(Pandoc meta blks) = do
+ let metaFnName = "Meta"
+ case Map.lookup metaFnName fnMap of
+ Nothing -> return pd
+ Just fn -> do
+ meta' <- runLuaFilterFunction lua fn meta
+ return $ Pandoc meta' blks
+
execBlockLuaFilter :: LuaState
-> FunctionMap
-> Block -> IO Block
diff --git a/test/lua/smallcaps-title.lua b/test/lua/smallcaps-title.lua
new file mode 100644
index 000000000..b839ee131
--- /dev/null
+++ b/test/lua/smallcaps-title.lua
@@ -0,0 +1,12 @@
+return {
+ {
+ Meta = function(meta)
+ -- The call to `MetaInlines` is redundant and used for testing purposes
+ -- only. The explicit use of a MetaValue constructor is only useful when
+ -- used with an empty table: `MetaInlines{}` is read differently than
+ -- `MetaBlocks{}`.
+ meta.title = pandoc.MetaInlines{pandoc.SmallCaps(meta.title)}
+ return meta
+ end
+ }
+}