9

Is it possible to write a custom output writer for Pandoc?

For example, suppose I want to convert a document:

pandoc -f markdown -t myCustomMarkup asdf.md

Does Pandoc have a way I can specify the conversion rules for myCustomMarkup? (e.g. I could specify that text that had the 'bold' attribute should map to <bold>text</bold>, and so on for all features/attributes that Pandoc recognises).

Can anyone point me to some documentation as to how I can implement my own? I can't seem to find any mention of this.

(Additionally, is there a way to "plug in" a writer defined in a file without having to (say) re-compile pandoc? e.g. pandoc -f markdown -t myCustomMarkup --writerpath=path/to/my/writer asdf.md)

1 Answer 1

8

There's no easy way to do this with current pandoc, but the next version of pandoc will contain code that allows you to write custom writers with a bit of easy lua scripting. (The code for this is already in the master branch in http://github.com/jgm/pandoc.) You'll be able to do

pandoc -t myfunkyformat.lua myfile.md

Here's an example of what a custom writer script might look like: https://github.com/jgm/pandoc/blob/master/data/sample.lua

You can use the code now if you compile from source: https://github.com/jgm/pandoc/wiki/Installing-the-development-version-of-pandoc

5
  • Last link is broken. Would it be possible to create a converter-extension, that removes custom parts of a document (e.g between something like <!-- <myexclusion> --> .. <!-- </myexclusion> --> for markdown), before passing it on to the standard converter for that input format?
    – naught101
    Commented Aug 13, 2013 at 5:15
  • See github.com/jgm/pandoc/blob/master/data/sample.lua (I'll edit the post above). Commented Aug 13, 2013 at 14:22
  • And yes, you could write a converter that does what you describe. The html comments would be passed to RawBlock, which could be told to set a global variable. The other functions could check this variable and emit no output if it is set. The variable could be reset when the end tag is reached. Commented Aug 13, 2013 at 14:23
  • 1
    What about Haskell? Is it possible to write a custom writer in Haskell without rebuilding the whole pandoc package?
    – boxdot
    Commented Jan 20, 2015 at 22:50
  • I'm also a little confused about the difference between Lua custom writers and another Haskell writer as mentioned by @finite Commented Aug 7, 2015 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.