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

fix output when converting binary #20

Open
wants to merge 3 commits 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
21 changes: 15 additions & 6 deletions lib/pandoc-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,27 @@ class << self
private

# Execute the pandoc command for binary writers. A temp file is created
# and written to, then read back into the program as a string, then the
# temp file is closed and unlinked.
# if there is no output and written to, then read back into the program
# as a string, then the temp file is closed and unlinked.
def convert_binary
tmp_file = Tempfile.new('pandoc-conversion')
begin
unless (self.option_string.include?('-o') && self.option_string.include?('--output'))
tmp_file = Tempfile.new('pandoc-conversion')
self.options += [{ :output => tmp_file.path }]
self.option_string = "#{self.option_string} --output #{tmp_file.path}"
end
begin
execute_pandoc
if tmp_file.nil?
option_tab = self.option_string.split(' ')
index = option_tab.rindex {|x| x == '--output' || x == '-o'}
return File.read(option_tab[index + 1])
end
return IO.binread(tmp_file)
ensure
tmp_file.close
tmp_file.unlink
unless tmp_file.nil?
tmp_file.close
tmp_file.unlink
end
end
end

Expand Down