Skip to content

Commit

Permalink
fix: do not dump file contents to string; closes #74
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed May 27, 2019
1 parent 0e82927 commit 0dff16d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/pandoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import childProcess from 'child_process'
import { pandocDataDir, pandocPath } from './boot'
import * as Pandoc from './pandoc-types'
import * as rpng from './rpng'
import { create, dump, load, VFile, write } from './vfile'
import { create, load, VFile, write } from './vfile'

export { InputFormat, OutputFormat } from './pandoc-types'

Expand All @@ -26,7 +26,7 @@ export async function parse(
ensureFile: boolean = false
): Promise<stencila.Node> {
const args = [`--from=${from}`, `--to=json`].concat(options)
let content = dump(file)
let content = file.contents
if (!content || ensureFile) {
if (ensureFile && !file.path) throw new Error('Must supply a file')
args.push(`${file.path}`)
Expand Down Expand Up @@ -95,13 +95,14 @@ let unparsePromises: Promise<any>[] = []
/**
* Run the Pandoc binary
*/
function run(input: string, args: string[]): Promise<string> {
function run(input: string | Buffer, args: string[]): Promise<string> {
args.push(`--data-dir=${pandocDataDir}`)
if (process.env.DEBUG) {
console.log(`Running ${pandocPath} with args:\n ${args.join('\n ')}`)
}
return new Promise((resolve, reject) => {
const child = childProcess.spawn(pandocPath, args)

let stdout = ''
let stderr = ''
child.stdout.on('data', data => {
Expand All @@ -121,8 +122,13 @@ function run(input: string, args: string[]): Promise<string> {
child.on('error', err => {
reject(err)
})
child.stdin.write(input)
child.stdin.end()

if (input.length) {
child.stdin.write(input, err => {
if (err) return reject(err)
child.stdin.end()
})
}
})
}

Expand Down

0 comments on commit 0dff16d

Please sign in to comment.