13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/ansispan.rb', line 13
def self.convert(str, escape_character: '\033')
escape_character = Regexp.escape(escape_character)
@foreground_colors.keys.each do |ansi|
span = '<span style="color: ' + @foreground_colors[ansi] + '">'
str = str.gsub(/#{escape_character}\[#{ansi}m/, span)
.gsub(/#{escape_character}\[#{ansi}m/, span)
end
str = str.gsub(/#{escape_character}\[1m/, '<b>')
.gsub(/#{escape_character}\[22m/, '</b>')
@foreground_colors.keys.each do |ansi|
span = '<span style="font-weight: bold; color: ' + @foreground_colors[ansi] + '">'
str = str.gsub(/#{escape_character}\[1;#{ansi}m/, span)
end
@foreground_colors.keys.each do |ansi|
span = '<span style="text-decoration: underline; color: ' + @foreground_colors[ansi] + '">'
str = str.gsub(/#{escape_character}\[4;#{ansi}m/, span)
end
str = str.gsub(/#{escape_character}\[3m/, '<i>')
.gsub(/#{escape_character}\[23m/, '</i>')
str = str.gsub(/#{escape_character}\[m/, '</span>');
str = str.gsub(/#{escape_character}\[0m/, '</span>');
return str.gsub(/#{escape_character}\[39m/, '</span>');
end
|