lib/shell2html.rb in shell2html-0.0.2 vs lib/shell2html.rb in shell2html-0.0.3

- old
+ new

@@ -44,17 +44,20 @@ "106" => { css: "sh_bg_lightcyan", style: { "background-color" => "#00ffff" } }, "107" => { css: "sh_bg_white", style: { "background-color" => "#ffffff" } } } def to_html(text, inline = false) + count = 0 text.gsub!(/\n/, '<br>') text.gsub!(/ /, ' &nbsp;') text.split(27.chr).map do |e| if /^\[([0-9;]+)m(.*)$/.match e case $1 when '0' - "</span>#{$2}" + span = '</span>' * count + count = 0 + "#{span}#{$2}" else key = $1 t = $2 css = [] key.split(';').each do |i| @@ -67,16 +70,19 @@ c[:style].each do |k,v| o << "#{k}:#{v}" end o end.flatten.join(';') - "<span style=\"#{span_style}\">#{t}" + count = 1 + "#{'</span>' * count}<span style=\"#{span_style}\">#{t}" else + count = 1 span_class = css.map { |c| c[:css] }.join(' ') - "<span class=\"#{span_class}\">#{t}" + "#{'</span>' * count}<span class=\"#{span_class}\">#{t}" end else - "<span>#{t}" + count = 1 + "#{'</span>' * count}<span>#{t}" end end else e end