Henrik
Henrik

Reputation: 1995

Pandoc Lua script to filter specific markdown sub sections during PDF generation

I have markdown source and want to generate PDF using Pandoc.

I want to remove ALL sub sections below a specified level in the generated document. E.g. filter them from the source markdown.

Would this be possible with Lua or would it be better to do prefiltering using some other tools?

Upvotes: 0

Views: 339

Answers (1)

Henrik
Henrik

Reputation: 1995

Got a suggestion from the Lua Google Groups forum which works for me:

local keep_deleting = false

function Block (b)
   if b.t == 'Header' and b.level >= 3 then
      keep_deleting = true
      return {}
   elseif b.t == 'Header' then
      keep_deleting = false
   elseif keep_deleting then
      return {}
   end
end

Upvotes: 2

Related Questions