File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33require 'kramdown'
44require 'erb'
55require 'stringio'
6-
6+ require 'base64'
77require 'optparse'
88
99require 'rubydown'
@@ -62,6 +62,9 @@ class EvalDoc < Kramdown::Document
6262 case
6363 when eval_result . respond_to? ( :to_html )
6464 Kramdown ::Document . new ( eval_result . to_html , input : :html ) . root
65+ when eval_result . instance_of? ( File ) && File . extname ( eval_result . path ) == ".png"
66+ img_b64 = Base64 . encode64 ( File . binread ( eval_result . path ) )
67+ Kramdown ::Document . new ( "<img src='data:image/png;base64,#{ img_b64 } ' />" , input : :html ) . root
6568 else
6669 text_result_el ( stdout_string + "=> #{ eval_result } " )
6770 end
Original file line number Diff line number Diff line change 55require 'numo/gnuplot'
66require 'base64'
77require 'tempfile'
8+ require 'charty'
89
910
1011class Numo ::NArray
@@ -29,6 +30,17 @@ def to_html
2930 end
3031end
3132
33+ Charty ::RenderContext . prepend Module . new {
34+ def render ( filename = nil )
35+ super
36+ if filename . nil?
37+ p "The image could not be rendered. In the environment without IRuby, the file name for the charty render method is required."
38+ else
39+ File . open ( filename )
40+ end
41+ end
42+ }
43+
3244module Rubydown
3345 class RbMarkPlot < Numo ::Gnuplot
3446 def plot ( *args )
Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ Gem::Specification.new do |spec|
4040 spec . add_dependency "numo-narray" , "~> 0.9.1"
4141 spec . add_dependency "numo-gnuplot" , "~> 0.2.4"
4242 spec . add_dependency "rbplotly" , "~> 0.1.2"
43+ spec . add_dependency "charty" , "0.1.1.dev"
44+ spec . add_dependency "matplotlib" , "~> 1.0.0"
4345
4446 spec . add_development_dependency "bundler" , "~> 1.17"
4547 spec . add_development_dependency "rake" , "~> 10.0"
You can’t perform that action at this time.
0 commit comments