Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use fenced code blocks in pandoc markdown output

Is there a way to make pandoc output fenced code blocks (i.e. using triple backticks) when outputting markdown, rather than indenting with four spaces?

like image 841
Timmmm Avatar asked Oct 17 '25 23:10

Timmmm


1 Answers

One can use a Lua filter to "manually" create the block output:

local fenced = '```\n%s\n```\n'
function CodeBlock (cb)
  -- use pandoc's default behavior if the block has classes or attribs
  if cb.classes[1] or cb.attributes[1] then
    return nil
  end
  return pandoc.RawBlock('markdown', fenced:format(cb.text))
end

Save the above to a file, then pass the file to pandoc via the --lua-filter option.

like image 74
tarleb Avatar answered Oct 19 '25 17:10

tarleb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!