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

- old
+ new

@@ -44,20 +44,23 @@ "106" => { css: "sh_bg_lightcyan", style: { "background-color" => "#00ffff" } }, "107" => { css: "sh_bg_white", style: { "background-color" => "#ffffff" } } } def to_html(text, inline = false) + 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}" else + key = $1 t = $2 css = [] - $1.split(';').each do |i| - css << COLORS["#{i}"] if COLORS["#{i}"] + key.split(';').each do |i| + css << COLORS["#{i.to_i}"] if COLORS["#{i.to_i}"] end if css.count > 0 if inline span_style = css.map do |c| o = [] @@ -79,10 +82,19 @@ e end end.join end - def to_css(text) + def css + back = [] + COLORS.each do |_, c| + o = [] + css = c[:style].each do |k, v| + o << "#{k}:#{v}" + end + back << ".#{c[:css]} { #{o.join(';')} }" + end + back.join("\n") end def to_sass(text) end