Lua filter: allow filtering of meta data only

This commit is contained in:
Albert Krewinkel 2017-04-16 21:06:50 +02:00 committed by Albert Krewinkel
parent 5416fb14ab
commit 9cd20c9b8b
2 changed files with 25 additions and 1 deletions

View file

@ -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

View file

@ -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
}
}