Class: AnsiArt::HtmlConverter

Inherits:
Converter show all
Defined in:
lib/ansi_art/html_converter.rb

Instance Method Summary collapse

Methods inherited from Converter

#reset_color, #set_color, #set_color_for, #wait_half_char!

Constructor Details

#initializeHtmlConverter

Returns a new instance of HtmlConverter.



3
4
5
6
# File 'lib/ansi_art/html_converter.rb', line 3

def initialize
  super
  @output = '<div><span class="f7 b0">'
end

Instance Method Details

#commit_colorObject



27
28
29
# File 'lib/ansi_art/html_converter.rb', line 27

def commit_color
  @output += '</span><span class="' + formatColor + '">'
end

#newLineObject



24
25
26
# File 'lib/ansi_art/html_converter.rb', line 24

def newLine
  @output += "</span></div><div><span class=\"#{formatColor}\">"
end

#outputObject



30
31
32
# File 'lib/ansi_art/html_converter.rb', line 30

def output
  return @output + '</span></div>'
end

#put(str) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ansi_art/html_converter.rb', line 7

def put str
  putHalfChar str[/./] unless @leftColor.nil?

  # behave like PCMan, need option for user to choose, though
  str.gsub!(/\u00B7/,"\u00B7 ")
  str.gsub!(/\u00A7/,"\u00A7 ")
  str.gsub!(/\uFF89/,"\uFF89 ")
  str.gsub!(/\u2665/,"\u2665 ")

  # HTML special chars
  str.gsub!(/&/, '&amp;')
  str.gsub!(/</, '&lt;')
  str.gsub!(/>/, '&gt;')
  str.gsub!(/"/, '&quot;')

  @output += str.gsub(/ /,'&nbsp;')
end