class TBBC def initialize self.conf(:configed_by => "system") end def conf(config) require 'rubygems' begin require 'uv' #UV Settings config[:syntax_output] ||= "html" config[:syntax_line_numbers] ||= true config[:syntax_theme] ||= "twilight" rescue LoadError config[:syntax_highlighting]=false end config[:configed_by] ||= "user" config[:image_alt] ||= "Posted Image" config[:url_target] ||= "_BLANK" config[:allow_defaults] ||= true #Instanize the config variable @config=config end def parse(s) #Run the UV Parser (if enabled) to sort out any code unless @config[:syntax_highlighting] == false s=uv s end #Remove the < and > which will disable all HTML s=s.gsub("<","<").gsub(">",">") unless @config[:disable_html] == false #Convert new lines to
's s=s.gsub(/\n/,'
') unless @config[:newline_enabled] == false #[nobbc] tags unless @config[:nobbc_enabled] == false s=nobbc s end #Loading Custom Tags begin if @config[:custom_tags] then @config[:custom_tags].each do |tag| s=s.gsub(tag[0],tag[1]) unless tag[2] == false end end rescue s+="
Custom Tags failed to run" end #Loading Default Tags and applying them if @config[:allow_defaults] then tags=load_default_tags tags.each do |tag| s=s.gsub(tag[0],tag[1]) unless tag[2] == false end end return s end def load_default_tags tags=[ #Bold [/\[b\](.*?)\[\/b\]/,'\1',@config[:strong_enabled]], #Italic [/\[i\](.*?)\[\/i\]/,'\1',@config[:italic_enabled]], #Underline [/\[u\](.*?)\[\/u\]/,'\1',@config[:underline_enabled]], #Url [/\[url\](.*?)\[\/url\]/,'\1',@config[:url_enabled]], [/\[url=(.*?)\](.*?)\[\/url\]/,'\2',@config[:url_enabled]], [/\[url=(.*?) target=(.*?)\](.*?)\[\/url\]/,'\3',@config[:url_enabled]], #Image [/\[img\](.*?)\[\/img\]/,''+ @config[:image_alt] + '',@config[:image_enabled]], [/\[img alt=(.*?)\](.*?)\[\/img\]/,'\1',@config[:image_enabled]], #Un-Ordered List [/\[ul\](.*?)\[\/ul\]/,'',@config[:list_enabled]], #Ordered List [/\[ol\](.*?)\[\/ol\]/,'
    \1
',@config[:list_enabled]], #List Item [/\[li\](.*?)\[\/li\]/,'
  • \1
  • ',@config[:list_enabled]], #Quote [/\[quote\](.*?)\[\/quote\]/,'
    \1
    ',@config[:quote_enabled]], [/\[quote=(.*?)\](.*?)\[\/quote\]/,'
    Posted by \1
    \2
    ',@config[:quote_enabled]], #Color [/\[color=(.*?)\](.*?)\[\/color\]/,'\2',@config[:color_enabled]], #Alignment [/\[center\](.*?)\[\/center\]/,'
    \1
    ',@config[:alignment_enabled]], [/\[left\](.*?)\[\/left\]/,'
    \1
    ',@config[:alignment_enabled]], [/\[right\](.*?)\[\/right\]/,'
    \1
    ',@config[:alignment_enabled]], #Acronym [/\[acronym=(.*?)\](.*?)\[\/acronym\]/,'\2',@config[:acronym_enabled]] ] end def nobbc(s) find=s.scan(/\[nobbc\](.*?)\[\/nobbc\]/) find.each do |f| replace=f[0].gsub("[","[").gsub("]","]") s=s.gsub("[nobbc]#{f[0]}[/nobbc]",replace) end return s end def css output="" output+=Uv.themes.map{|theme| %Q(\n)} return output end def uv(s) find=s.scan(/\[code lang=(.*?)\](.*?)\[\/code\]/) find.each do |f| #parse=nobbc "[nobbc]" + f[1] + "[/nobbc]" r=Uv.parse(f[1], @config[:syntax_output], f[0], @config[:syntax_line_numbers], @config[:syntax_theme]) end s=s.gsub(/\[code lang=(.*?)\]/,'').gsub("[/code]",'') return s end end #Add .tbbc to Strings class String def tbbc(conf = nil) bbc=TBBC.new bbc.conf(conf) if conf bbc.parse(self) end end