mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-22 23:45:48 +00:00
Lua filters: allow filtering of element lists (#6040)
Lists of Inline and Block elements can now be filtered via `Inlines` and
`Blocks` functions, respectively. This is helpful if a filter conversion
depends on the order of elements rather than a single element.
For example, the following filter can be used to remove all spaces
before a citation:
function isSpaceBeforeCite (spc, cite)
return spc and spc.t == 'Space'
and cite and cite.t == 'Cite'
end
function Inlines (inlines)
for i = #inlines-1,1,-1 do
if isSpaceBeforeCite(inlines[i], inlines[i+1]) then
inlines:remove(i)
end
end
return inlines
end
Closes: #6038
This commit is contained in:
committed by
John MacFarlane
parent
400b29d10e
commit
672a4bdd1d
@@ -0,0 +1,8 @@
|
||||
function Blocks (blks)
|
||||
-- verify that this looks like a `pandoc.List`
|
||||
if not blks.find or not blks.map or not blks.filter then
|
||||
error("table doesn't seem to be an instance of pandoc.List")
|
||||
end
|
||||
-- return plain block containing the number of elements in the list
|
||||
return {pandoc.Plain {pandoc.Str(tostring(#blks))}}
|
||||
end
|
||||
Reference in New Issue
Block a user