module RedCloth::Formatters::HTML

def clean_html( text, allowed_tags = BASIC_TAGS )

Clean unauthorized tags.
def clean_html( text, allowed_tags = BASIC_TAGS )
  text.gsub!( /<!\[CDATA\[/, '' )
  text.gsub!( /<(\/*)([A-Za-z]\w*+)([^>]*?)(\s?\/?)>/ ) do |m|
    raw = $~
    tag = raw[2].downcase
    if allowed_tags.has_key? tag
      pcs = [tag]
      allowed_tags[tag].each do |prop|
        ['"', "'", ''].each do |q|
          q2 = ( q != '' ? q : '\s' )
          if raw[3] =~ /#{prop}\s*=\s*#{q}([^#{q2}]+)#{q}/i
            attrv = $1
            next if (prop == 'src' or prop == 'href') and not attrv =~ %r{^(http|https|ftp):}
            pcs << "#{prop}=\"#{attrv.gsub('"', '\\"')}\""
            break
          end
        end
      end if allowed_tags[tag]
      "<#{raw[1]}#{pcs.join " "}#{raw[4]}>"
    else # Unauthorized tag
      if block_given?
        yield m
      else
        ''
      end
    end
  end
end