pandocwriter

Customize the Pandoc writer for the ConTeXt output format?


I'm currently trying to customize the standard writer built into Pandoc to produce output in the ConTeXt format from Markdown input. Unfortunately, the documentation to create a custom writer found at the Pandoc website is not giving me too much information apart from how to write a custom HTML writer. So, I would like to ask for help with some fundamental ideas:

I know that these questions may sound rather simple, but there doesn't seem to be a lot of information available beyond the usual basic stuff. Any help would be much appreciated.


Solution

  • Pandoc has another feature that is similar to custom writers, called "Lua filters". Filters are quite likely a simpler and better choice in this case: They allow to modify the internal document representation. E.g.:

    function Inlines (inlines)
      for i=#inlines, 3, -1 do  -- iterate backwards through the list of inlines
        if inlines[i-2].t == 'Space' and inline[i-1] == pandoc.Str '-' and
           inlines[i].t == 'Space' then
          -- Replace elements with raw ConTeXt
          inlines[i-2] = pandoc.RawInline('context', '~--')
          inlines:remove(i)
          inlines:remove(i-1)
        end
      end
      return inlines
    end
    

    The above would be used b writing it to a file, and then passing that file to pandoc via --lua-filters FILENAME.lua

    The documentation for Lua filters is also less sparse and hopefully more approachable than the docs for custom writers.