Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,19 +493,31 @@ async function ConvertImageWithSnipAPI(authToken, outputType, source, destinatio
process.stdout.cursorTo(0);

let responseJSON = await res.json();
if (responseJSON.errors !== undefined) {
console.error("Error(s) encountered:\n");
console.error(responseJSON.errors);
return process.exit(1);
}
let textDisplay = responseJSON["text_display"];
if (textDisplay === undefined) {
console.error("No LaTeX found in response:\n");
console.error(responseJSON);
return process.exit(1);
}

if (destination.endsWith("docx")) {
await MarkdownToDocx(responseJSON["text_display"], destination, true);
await MarkdownToDocx(textDisplay, destination, true);
} else if (destination.endsWith("tex")) {
await MarkdownToTex(responseJSON["text_display"], destination, true);
await MarkdownToTex(textDisplay, destination, true);
} else if (destination.endsWith("pdf") && htmlPDF) {
await MarkdownToHTMLPDF(responseJSON["text_display"], destination, true);
await MarkdownToHTMLPDF(textDisplay, destination, true);
} else if (destination.endsWith("pdf")) {
await MarkdownToLatexPDF(responseJSON["text_display"], destination, true);
await MarkdownToLatexPDF(textDisplay, destination, true);
} else if (destination.endsWith("html")) {
await MarkdownToHTML(responseJSON["text_display"], destination, true);
await MarkdownToHTML(textDisplay, destination, true);
} else {
try {
fs.writeFileSync(destination, responseJSON["text_display"]);
fs.writeFileSync(destination, textDisplay);
} catch (err) {
console.log(`Could not write to destination path: ${destination}`);
return process.exit(1);
Expand Down Expand Up @@ -565,19 +577,25 @@ async function ConvertImageWithOCRAPI(apiKey, outputType, source, destination, h
process.stdout.cursorTo(0);

let responseJSON = await res.json();
let latex = responseJSON["text"];
if (latex === undefined) {
console.error("No LaTeX found in response:\n");
console.error(responseJSON);
return process.exit(1);
}
if (destination.endsWith("docx")) {
await MarkdownToDocx(responseJSON["latex_styled"], destination, true);
await MarkdownToDocx(latex, destination, true);
} else if (destination.endsWith("tex")) {
await MarkdownToTex(responseJSON["latex_styled"], destination, true);
await MarkdownToTex(latex, destination, true);
} else if (destination.endsWith("pdf") && htmlPDF) {
await MarkdownToHTMLPDF(responseJSON["latex_styled"], destination, true);
await MarkdownToHTMLPDF(latex, destination, true);
} else if (destination.endsWith("pdf")) {
await MarkdownToLatexPDF(responseJSON["latex_styled"], destination, true);
await MarkdownToLatexPDF(latex, destination, true);
} else if (destination.endsWith("html")) {
await MarkdownToHTML(responseJSON["latex_styled"], destination, true);
await MarkdownToHTML(latex, destination, true);
} else {
try {
fs.writeFileSync(destination, responseJSON["latex_styled"]);
fs.writeFileSync(destination, latex);
} catch (err) {
console.log(`Could not write to destination path: ${destination}`);
return process.exit(1);
Expand Down