diff --git a/doc/lua-filters.md b/doc/lua-filters.md index 8b8dbfc47..0ac8a22f0 100644 --- a/doc/lua-filters.md +++ b/doc/lua-filters.md @@ -40,11 +40,9 @@ to small caps: ``` lua return { - { - Strong = function (elem) - return pandoc.SmallCaps(elem.content) - end, - } + Strong = function (elem) + return pandoc.SmallCaps(elem.content) + end, } ``` @@ -187,7 +185,7 @@ local filter = { traverse = 'topdown', -- ... filter functions ... } -return {filter} +return filter ``` Support for this was added in pandoc 2.17; previous versions diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Filter.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Filter.hs index 4728f961e..40ccb2f8f 100644 --- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Filter.hs +++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Filter.hs @@ -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 diff --git a/pandoc-lua-engine/test/lua/single-to-double-quoted.lua b/pandoc-lua-engine/test/lua/single-to-double-quoted.lua index b985b215c..29843df06 100644 --- a/pandoc-lua-engine/test/lua/single-to-double-quoted.lua +++ b/pandoc-lua-engine/test/lua/single-to-double-quoted.lua @@ -1,10 +1,8 @@ return { - { Quoted = function (elem) if elem.quotetype == "SingleQuote" then elem.quotetype = "DoubleQuote" end return elem end, - } }