Lua filter: allow filtering of meta data only
This commit is contained in:
parent
5416fb14ab
commit
9cd20c9b8b
2 changed files with 25 additions and 1 deletions
|
@ -75,7 +75,8 @@ runAll (x:xs) = walkMWithLuaFilter x >=> runAll xs
|
||||||
walkMWithLuaFilter :: LuaFilter -> Pandoc -> IO Pandoc
|
walkMWithLuaFilter :: LuaFilter -> Pandoc -> IO Pandoc
|
||||||
walkMWithLuaFilter (LuaFilter lua fnMap) =
|
walkMWithLuaFilter (LuaFilter lua fnMap) =
|
||||||
walkM (execInlineLuaFilter lua fnMap) >=>
|
walkM (execInlineLuaFilter lua fnMap) >=>
|
||||||
walkM (execBlockLuaFilter lua fnMap) >=>
|
walkM (execBlockLuaFilter lua fnMap) >=>
|
||||||
|
walkM (execMetaLuaFilter lua fnMap) >=>
|
||||||
walkM (execDocLuaFilter lua fnMap)
|
walkM (execDocLuaFilter lua fnMap)
|
||||||
|
|
||||||
type FunctionMap = Map String LuaFilterFunction
|
type FunctionMap = Map String LuaFilterFunction
|
||||||
|
@ -92,6 +93,17 @@ execDocLuaFilter lua fnMap x = do
|
||||||
Nothing -> return x
|
Nothing -> return x
|
||||||
Just fn -> runLuaFilterFunction lua fn 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
|
execBlockLuaFilter :: LuaState
|
||||||
-> FunctionMap
|
-> FunctionMap
|
||||||
-> Block -> IO Block
|
-> Block -> IO Block
|
||||||
|
|
12
test/lua/smallcaps-title.lua
Normal file
12
test/lua/smallcaps-title.lua
Normal 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue