Skip to content

Instantly share code, notes, and snippets.

@BartzLeon
Created August 26, 2021 12:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BartzLeon/5e5f8fae907860b94033ac5d0affbfe2 to your computer and use it in GitHub Desktop.
Save BartzLeon/5e5f8fae907860b94033ac5d0affbfe2 to your computer and use it in GitHub Desktop.
const spawn = require('child_process').spawn;
const pandocPath = process.env.PANDOC || 'pandoc';
let args = ['-f', from, '-t', to, '-o', 'output/' + outputFile, inputFile];
let pandoc = spawn(pandocPath, args);
let error = '';
pandoc.on('error', (err) => (throw new Error(err)));
pandoc.stderr.on('data', (data) => error += data);
pandoc.on('close', (code) => {
if (code !== 0) {
let msg = 'Pandoc finished with exit code ' + code;
if (error) {
msg += ':' + error;
}
reject(msg);
} else {
console.log('Pandoc finished successfully');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment