class TBBC def initialize self.conf(:configed_by => "system") end def conf(config) config[:configed_by] ||= "user" config[:image_alt] ||= "Posted Image" config[:url_target] ||= "_BLANK" @config=config end def parse(s) #First off remove the < and > which will disable all HTML s=s.gsub("<","<").gsub(">",">") #Convert new lines to
's s=s.gsub(/\n/,'
') #Loading Custom Tags if @config[:custom_tags] then @config[:custom_tags].each do |tag| s=s.gsub(tag[0],tag[1]) unless tag[2] == false end end #Loading Default Tags and applying them tags=load_default_tags tags.each do |tag| s=s.gsub(tag[0],tag[1]) unless tag[2] == false end return s end def load_default_tags tags=[ [/\[b\](.*?)\[\/b\]/,'\1',@config[:strong_enabled]], [/\[i\](.*?)\[\/i\]/,'\1',@config[:italic_enabled]], [/\[u\](.*?)\[\/u\]/,'\1',@config[:underline_enabled]], [/\[url\](.*?)\[\/url\]/,'\1',@config[:url_enabled]], [/\[url=(.*?)\](.*?)\[\/url\]/,'\2',@config[:url_enabled]], [/\[img\](.*?)\[\/img\]/,''+ @config[:image_alt] + '',@config[:image_enabled]], [/\[img alt=(.*?)\](.*?)\[\/img\]/,'\1',@config[:image_enabled]] ] end end class String def tbbc bbc=TBBC.new bbc.parse(self) end end