Your filter looks good, except that any subsection of the "marked" section will remain present... but perhaps that's what you want.
If not, or if anyone else would like to remove all subsections of that section, the following seems to work:
local looking_at_section = false
local remove = {}
local lvl = 0
function Block (elem)
if looking_at_section then
remove[#remove + 1] = elem
return {}
end
end
function Header (elem)
if elem.identifier == 'remove' then
looking_at_section = true
lvl = elem.level
return {}
else
looking_at_section = looking_at_section and elem.level > lvl
if looking_at_section then
remove[#remove + 1] = elem
return {}
end
end
end
The original filter has the same problem... but an abstract usually doesn't have subsections/sublevels (I think).
Note also that usually an identifier should identify only one element, and pandoc will (rightly) be annoyed when there's more than one header with the same ID.
A class would be ideal for this situation, and one might then use `if elem.classes:includes(
'remove'
,1)
` rather than `if elem.identifier == 'remove'`