Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kenyonj committed Jun 14, 2024
1 parent 5654dc7 commit abc78fd
Show file tree
Hide file tree
Showing 5 changed files with 617 additions and 496 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
source "http://rubygems.org"
gemspec

gem "posix-spawn", :platforms => :ruby
gem "redcarpet", :platforms => :ruby
gem "kramdown", :platforms => :jruby
gem "RedCloth"
Expand Down
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Bump nokogiri from 1.8.1 to 1.16.5
* Bump nokogiri-diff from 0.2.0 to 0.3.0
* Bump rdoc from 3.6 to 6.7.0
* Update CommandImplementation to better support large files (affecting RST and POD6 rendering)

## 4.0.2 - 2023-10-10
* Add support for .mdx files in markdown
Expand Down
36 changes: 8 additions & 28 deletions lib/github/markup/command_implementation.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
begin
require "posix-spawn"
rescue LoadError
require "open3"
end

require "open3"
require "github/markup/implementation"


Expand Down Expand Up @@ -39,28 +34,13 @@ def call_block(rendered, content)
end
end

if defined?(POSIX::Spawn)
def execute(command, target)
spawn = POSIX::Spawn::Child.new(*command, :input => target)
if spawn.status.success?
sanitize(spawn.out, target.encoding)
else
raise CommandError.new(spawn.err.strip)
end
end
else
def execute(command, target)
output = Open3.popen3(*command) do |stdin, stdout, stderr, wait_thr|
stdin.puts target
stdin.close
if wait_thr.value.success?
stdout.readlines
else
raise CommandError.new(stderr.readlines.join('').strip)
end
end
sanitize(output.join(''), target.encoding)
end
def execute(command, target)
# capture3 blocks until both buffers are written to and the process terminates, but
# it won't allow either buffer to fill up
stdout, stderr, status = Open3.capture3(*command, stdin_data: target)

raise CommandError.new(stderr) unless status.success?
sanitize(stdout, target.encoding)
end

def sanitize(input, encoding)
Expand Down
2 changes: 1 addition & 1 deletion test/markup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_raises_error_if_command_exits_non_zero
begin
GitHub::Markup.render('README.java', "stop swallowing errors", symlink: false)
rescue GitHub::Markup::CommandError => e
assert_equal "failure message", e.message
assert_equal "failure message", e.message.strip
else
fail "an exception was expected but was not raised"
end
Expand Down
Loading

0 comments on commit abc78fd

Please sign in to comment.