# File lib/facet/bbcode.rb, line 229
    def BBCode.html_to_bbcode(string)
        return "" if string.nil? || string.to_s.strip.empty?
        result = ""

        ## Iterate over lines
        string.split(/<br *\/?>/i).each do |line|
            styles = { "strong" => "b", "b" => "b",
                       "em"     => "i", "i" => "i",
                       "u"      => "u" }

            ## preserve B, I, U
            styles.each do |html,code|
                line.gsub!(/<#{html}>/i, "[#{code.upcase}]")
                line.gsub!(/<\/#{html}>/i, "[/#{code.upcase}]")
            end
            
            ## TODO: COLORs
            ## TODO: SIZEs
            ## TODO: FONTs

            ## EMAIL
            line.gsub!(/<a +href *= *\"mailto:(.*?)\".*?>.*?<\/a>/i, "[EMAIL]\\1[/EMAIL]")
            
            ## URL
            line.gsub!(/<a +href *= *\"((?:https?|ftp):\/\/.*?)\".*?>(.*?)<\/a>/i, "[URL=\\1]\\2[/URL]")
            
            ## Other refs + closing tags => throw away
            line.gsub!(/<a +href *= *\".*?\".*?>/i, "")
            line.gsub!(/<\/a>/i,            "")

            ## IMG
            line.gsub!(/<img +src *= *\"(.*?)\".*?\/?>/i, "[IMG=\\1]")

            ## CENTER (right/left??)
            line.gsub!(/<center>/i,   "[ALIGN=center]")
            line.gsub!(/<\/center>/i, "[/ALIGN]")

            ## QUOTE
            line.gsub!(/<(?:xmp|pre)>/i,   "[QUOTE]")
            line.gsub!(/<\/(?:xmp|pre)>/i, "[/QUOTE]")

            ## LIST
            line.gsub!(/<ul>/i,      "\n[LIST]\n")
            line.gsub!(/<\/ul>/i,    "\n[/LIST]\n")
            line.gsub!(/<li *\/?> */i, "\n[*] ")

            ## Unkown tags => throw away
            line.gsub!(/<.*? *\/?>/, "")

            result << sprintf("%s<br />\n", line)
        end

        return result.gsub!(/<br *\/?>/i, "\n")
    end