Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to read longer files from stdin #364

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
23 changes: 13 additions & 10 deletions src/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ exports.render = (input, options, done) ->

done null, html, res.warnings

process_stdin = (processor) ->
process.stdin.setEncoding 'utf-8'
chunks = []
process.stdin.on 'readable', ->
while (chunk = process.stdin.read()) != null
chunks.push chunk
process.stdin.on 'end', ->
content = chunks.join ''
if content?
processor content

# Render from/to files
exports.renderFile = (inputFile, outputFile, options, done) ->
render = (input) ->
Expand All @@ -139,11 +150,7 @@ exports.renderFile = (inputFile, outputFile, options, done) ->
if err then return done(errMsg 'Error reading input', err)
render input.toString()
else
process.stdin.setEncoding 'utf-8'
process.stdin.on 'readable', ->
chunk = process.stdin.read()
if chunk?
render chunk
process_stdin render

# Compile markdown from/to files
exports.compileFile = (inputFile, outputFile, done) ->
Expand All @@ -162,8 +169,4 @@ exports.compileFile = (inputFile, outputFile, done) ->
if err then return done(errMsg 'Error writing output', err)
compile input.toString()
else
process.stdin.setEncoding 'utf-8'
process.stdin.on 'readable', ->
chunk = process.stdin.read()
if chunk?
compile chunk
process_stdin compile