Pandoc Jupyter filter to allow/prevent code blocks

16 views Asked by At

I'm (mostly successfully) converting Jupyter to LaTex.

I can allow/prevent Jupyter code blocks from appearing in the LaTex by using this Lua filter:

function Div(el)
  if el.classes:includes("code") then
    if el.content[1].t == "CodeBlock" then
      el.content:remove(1)
    end
  end
  return el
end

Now looking for a Lua filter or other solution to prevent only those Jupyter code blocks that are set to not display. Can you help me? Alternatively, how about a filter to prevent only Jupyter code blocks that contain specific text?

Many thanks.

1

There are 1 answers

0
Richard Huntsinger On

Ah, here's the solution:

function Div(el)
  if el.classes:includes("code") then
    if el.attributes['hide_input'] == "true" then
      if el.content[1].t == "CodeBlock" then
        el.content:remove(1)
      end
    end
  end
  return el
end