Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
now passes pandoc errors back to you
Browse files Browse the repository at this point in the history
  • Loading branch information
jgnewman committed Nov 14, 2012
1 parent 95c6e9e commit 5246c32
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions lib/procedure.js
Expand Up @@ -89,6 +89,24 @@ function getOutputFormat(formatVar, outputVar) {
return getFileExtension(outputVar);
}

/*
* If Pandoc gives us an error warning, pass it on
* to the user.
*/
function catchWarning(err, stdout, stderr) {
if (stdout) {
console.log(stdout.replace(/^pandoc:\s/, 'jandoc: ').replace(/\n*$/, ''));
}

if (stderr) {
console.log(stderr.replace(/^pandoc:\s/, 'jandoc: ').replace(/\n*$/, '\njandoc: conversion was unsuccessful.'));
}

if (err) {
process.exit(1);
}
}

/*
* Builds a Pandoc command line command.
*/
Expand Down Expand Up @@ -132,15 +150,15 @@ function runCommand(inputPath, outputPath, outputFormat, argString) {
* Build the command and run it.
*/
command = buildCommand(inputPath + '/' + files[i], outputPath + '/' + files[i], outputFormat, argString);
cmdLine(command, null);
cmdLine(command, catchWarning);

/*
* Otherwise, the input is a file and the output is a file.
* Build the command and run it.
*/
} else {
command = buildCommand(inputPath + '/' + files[i], outputPath, outputFormat, argString);
cmdLine(command, null);
cmdLine(command, catchWarning);
}
}
}
Expand All @@ -166,15 +184,15 @@ function runCommand(inputPath, outputPath, outputFormat, argString) {
* Build the command and run it.
*/
command = buildCommand(inputPath, outputPath + '/' + getFileName(inputPath), outputFormat, argString);
cmdLine(command, null);
cmdLine(command, catchWarning);

/*
* Otherwise, the input is a file and the output is a file.
* Build the command and run it.
*/
} else {
command = buildCommand(inputPath, outputPath, outputFormat, argString);
cmdLine(command, null);
cmdLine(command, catchWarning);
}
}
}
Expand Down

0 comments on commit 5246c32

Please sign in to comment.