One can simplify further I think[^1], removing a redundancy:

local looking_at_section = false
local lvl = 0
local remove = {}  -- delete line if 'remove' array not needed

function Block (elem)
 
if elem.t == "Header" then
   
-- if elem.classes:includes('remove',1) then
   
if elem.identifier == 'remove' then
      looking_at_section
= true
      lvl
= elem.level
   
else
      looking_at_section
= looking_at_section and elem.level > lvl
   
end
 
end
 
if looking_at_section then
    remove
[#remove + 1] = elem  -- delete line if 'remove' array not needed
   
return {}
 
end
end

Note that in the original "abstract" script example, the removed portion was recreated as a meta section. If you don't intend to use the removed elements, you can simplify further (as noted) by removing the two lines related to the remove{} array.

[^1]: As long as the filter acts from top to bottom of document among the Blocks, i.e. if there's no unknown precedence rules among all the Block types... which I'm not 100% sure.

--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/50ee8006-c909-4b7f-a81b-98d83c2a4aa9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.