mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-24 15:44:59 +08:00
Lua: allow returning a single filter from filter files
It is now possible to return a single filter from a filter file, e.g.
``` lua
-- Switch single- and double quotes
return {
Quoted = function (q)
elem.quotetype = elem.quotetype == 'SingleQuote'
and 'DoubleQuote' or 'SingleQuote'
return elem
end
}
The filter must not contain numerical indexes, or it might be treated as
a list of filters.
This commit is contained in:
@@ -43,7 +43,10 @@ runFilterFile' envIdx filterPath doc = do
|
||||
-- filter if nothing was returned.
|
||||
luaFilters <- forcePeek $
|
||||
if newtop - oldtop >= 1
|
||||
then peekList peekFilter top -- get from explicit filter table
|
||||
then liftLua (rawlen top) >>= \case
|
||||
-- explicitly returned filter, either a single one or a list
|
||||
0 -> (:[]) <$!> peekFilter top -- single filter
|
||||
_ -> peekList peekFilter top -- list of explicit filters
|
||||
else (:[]) <$!> peekFilter envIdx -- get the implicit filter in _ENV
|
||||
settop oldtop
|
||||
runAll luaFilters doc
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
return {
|
||||
{
|
||||
Quoted = function (elem)
|
||||
if elem.quotetype == "SingleQuote" then
|
||||
elem.quotetype = "DoubleQuote"
|
||||
end
|
||||
return elem
|
||||
end,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user