class TBBC def initialize self.conf(:configed_by => "system") end def conf(config) require 'rubygems' require 'coderay' config[:configed_by] ||= "user" config[:image_alt] ||= "Posted Image" config[:url_target] ||= "_BLANK" config[:allow_defaults] ||= true config[:table_width] ||= "100%" config[:syntax_highlighting] ||= true config[:syntax_highlighting_html] ||= "color: #E7BE69" config[:syntax_highlighting_comment] ||= "color:#BC9358; font-style: italic;" config[:syntax_highlighting_escaped] ||= "color:#509E4F" config[:syntax_highlighting_class] ||= "color:#FFF" config[:syntax_highlighting_constant] ||= "color:#FFF" config[:syntax_highlighting_float] ||= "color:#A4C260" config[:syntax_highlighting_function] ||= "color:#FFC56D" config[:syntax_highlighting_global] ||= "color:#D0CFFE" config[:syntax_highlighting_integer] ||= "color:#A4C260" config[:syntax_highlighting_inline] ||= "background:#151515" config[:syntax_highlighting_instance] ||= "color:#D0CFFE" config[:syntax_highlighting_doctype] ||= "color:#E7BE69" config[:syntax_highlighting_keyword] ||= "color:#CB7832" config[:syntax_highlighting_regex] ||= "color:#A4C260" config[:syntax_highlighting_string] ||= "color:#A4C260" config[:syntax_highlighting_symbol] ||= "color:#6C9CBD" config[:syntax_highlighting_html] ||= "color:#E7BE69" config[:syntax_highlighting_boolean] ||= "color:#6C9CBD" #Instanize the config variable @config=config end def parse(s) #CodeRay s=coderay(s) #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 s=nobbc s unless @config[:nobbc_enabled] == false #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 s=correctbrs s 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]], #Tables #Table Tag [/\[table\](.*?)\[\/table\]/,'\1
    ',@config[:table_enabled]], #Table Elements [/\[tr\](.*?)\[\/tr\]/,'\1',@config[:table_enabled]], [/\[td\](.*?)\[\/td\]/,'\1',@config[:table_enabled]], [/\[th\](.*?)\[\/th\]/,'\1',@config[:table_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="" return output end def correctbrs(s) #Corrects the extra brs s=s.gsub(/
    <(ul|li|table|tr|td|th)/,'<\1') s=s.gsub(/
    <\/(ul|li|table|tr|td|th)/,' :class) + "[/nobbc]" end 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