def BBCode.bbcode_to_html(string)
return "" if string.nil? || string.to_s.strip.empty?
result = ""
quote = 0
string.split("\n").each do |line|
styles = { "b" => "strong", "i" => "em", "u" => "u" }
styles.each do |code,html|
line.gsub!(/\[#{code}\]/i, "<#{html}>")
line.gsub!(/\[\/#{code}\]/i, "</#{html}>")
end
line.gsub!(/\[COLOR=(.*?)\]/i, "<font color=\"\\1\">")
line.gsub!(/\[\/COLOR\]/i, "</font>")
line.gsub!(/\[SIZE=(.*?)\]/i, "<font size=\"\\1\">")
line.gsub!(/\[\/SIZE\]/i, "</font>")
line.gsub!(/\[URL\]([^\[]+?)\[\/URL\]/i, "<a href=\"\\1\">\\1</a>")
line.gsub!(/\[URL=(.*?)\](.+?)\[\/URL\]/i, "<a href=\"\\1\">\\2</a>")
line.gsub!(/\[IMG=(.*?)\]/i, "<img src=\"\\1\" />")
line.gsub!(/\[ALIGN=center\]/i, "<center>")
line.gsub!(/\[ALIGN=right\]/i, "<center>")
line.gsub!(/\[ALIGN=left\]/i, "<center>")
line.gsub!(/\[\/ALIGN\]/i, "</center>")
quote+=1 if line =~ /\[QUOTE\]/i
quote-=1 if (line =~ /\[\/QUOTE\]/i) && (quote > -1)
line.gsub!(/\[QUOTE\]/i, "<pre>\n")
line.gsub!(/\[\/QUOTE\]/i, "</pre>\n")
line.gsub!(/^/, ">"*quote) if quote > 0
line.gsub!(/\[EMAIL\](.*?)\[\/EMAIL\]/i, "<a href=\"mailto:\\1\">\\1</a>")
line.gsub!(/\[LIST(?:=(.*?))?\]/i, "\n<ul>\n")
line.gsub!(/\[\/LIST\]/i, "\n</ul>\n")
line.gsub!(/\[\*\]/i, "\n<li />")
result << sprintf("%s<br />\n", line)
end
return result
end