Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write a custom converter for Pandoc?

Tags:

pandoc

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)

like image 434
mathematical.coffee Avatar asked Apr 11 '13 01:04

mathematical.coffee


People also ask

Can pandoc convert from PDF?

You can use the program pandoc on the SCF Linux and Mac machines (via the terminal window) to convert from formats such as HTML, LaTeX and Markdown to formats such as HTML, LaTeX, Word, OpenOffice, and PDF, among others.

Can pandoc convert HTML to Markdown?

Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx.

How do I convert Word to Markdown in pandoc?

As you can see, first, write pandoc to execute any pandoc command, and then write the file name of a file with extension which you want to convert to a markdown file. The -o stands for output file name and provide name of the file with extension to which it should be converted.


1 Answers

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

like image 177
John MacFarlane Avatar answered Nov 25 '22 12:11

John MacFarlane