An image of Heer de Beer

Heer de

Exploring the Computational Medium

Paja, Pandoc wrapped around in JavaScript

Huub de Beer

July, 2016

Paja is a simple JavaScript wrapper around pandoc, the great multi-format document converter. Paja is inspired by Paru, a Ruby wrapper for pandoc that I wrote earlier. Like Paru, Paja supports automating the use of pandoc. Paja is free software; Paja is licensed under the GNU General Public Licence version 3. Get the code at

The current version of Paja is 0.0.3, which is an alpha version.


Because Paja is a wrapper around pandoc, pandoc is obviously a requirement for Paja. Install Paja with npm:

npm install paja


The obligatory “hello world” program with paja:

const paja = require("paja");
const INPUT = `
> Hello World! 

from **Paja**`;

const markdown2html = paja.Pandoc
    .to("html");, console.log);

which will output:

<p>Hello World!</p>
<p>from <strong>Paja</strong></p>

All of pandoc’s long-style command line options are mapped to a method of the Pandoc class. Option names without the prefix “--” are converted to camelCase method names. For example:

The table of contents’s short option is actually also supported—I got tired of typing the long form quite fast as I use that option often—so Pandoc.toc() works as well.

Pandoc can also be used as a transform stream. This makes it easy to pipe some read stream through pandoc. For example, this documentation file, can be converted to HTML and outputted to STDOUT as follows:

const paja = require("paja");
const fs = require("fs");

const md2html = paja.Pandoc

const INPUT_FILE = "";

fs.createReadStream(INPUT_FILE, {encoding: "utf8"})

Observe that the Pandoc.css method is called twice; Pandoc adds both stylesheets to the HEAD element of the generated HTML. All pandoc’s command line options that can occur more than once, such as --include-in-header or --variable, have the same behavior: you can call these methods as often as you like.