Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion exe/rubydown
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'kramdown'
require 'erb'
require 'stringio'

require 'base64'
require 'optparse'

require 'rubydown'
Expand Down Expand Up @@ -62,6 +62,9 @@ class EvalDoc < Kramdown::Document
case
when eval_result.respond_to?(:to_html)
Kramdown::Document.new(eval_result.to_html, input: :html).root
when eval_result.instance_of?(File) && File.extname(eval_result.path) == ".png"
img_b64 = Base64.encode64(File.binread(eval_result.path))
Kramdown::Document.new("<img src='data:image/png;base64,#{img_b64}' />", input: :html).root
else
text_result_el(stdout_string + "=> #{eval_result}")
end
Expand Down
12 changes: 12 additions & 0 deletions lib/rubydown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'numo/gnuplot'
require 'base64'
require 'tempfile'
require 'charty'


class Numo::NArray
Expand All @@ -29,6 +30,17 @@ def to_html
end
end

Charty::RenderContext.prepend Module.new {
def render(filename=nil)
super
if filename.nil?
p "The image could not be rendered. In the environment without IRuby, the file name for the charty render method is required."
else
File.open(filename)
end
end
}

module Rubydown
class RbMarkPlot < Numo::Gnuplot
def plot(*args)
Expand Down
2 changes: 2 additions & 0 deletions rubydown.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Gem::Specification.new do |spec|
spec.add_dependency "numo-narray", "~> 0.9.1"
spec.add_dependency "numo-gnuplot", "~> 0.2.4"
spec.add_dependency "rbplotly", "~> 0.1.2"
spec.add_dependency "charty", "0.1.1.dev"
spec.add_dependency "matplotlib", "~> 1.0.0"

spec.add_development_dependency "bundler", "~> 1.17"
spec.add_development_dependency "rake", "~> 10.0"
Expand Down