lib/trainbbcode.rb in trainbbcode-0.3.1 vs lib/trainbbcode.rb in trainbbcode-0.3.2
- old
+ new
@@ -28,18 +28,19 @@
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"
+ config[:syntax_highlighting_line_numbers]||= :inline
#Instanize the config variable
@config=config
end
def parse(s)
#Remove the < and > which will disable all HTML
s=s.gsub("<","<").gsub(">",">") unless @config[:disable_html] == false
#CodeRay
- s=coderay(s)
+ s=coderay(s) unless @config[:syntax_highlighting] == false
#Convert new lines to <br />'s
s=s.gsub(/\n/,'<br />') unless @config[:newline_enabled] == false
#[nobbc] tags
s=nobbc s unless @config[:nobbc_enabled] == false
#Loading Custom Tags
@@ -152,15 +153,14 @@
def correctbrs(s)
#Corrects the extra brs
s=s.gsub(/<br \/><(ul|li|table|tr|td|th)/,'<\1')
s=s.gsub(/<br \/><\/(ul|li|table|tr|td|th)/,'</\1')
end
- def coderay(s)
-
- s.gsub(/\[code( lang=(.+?))?\](.+?)\[\/code\]/m) do
- parse=$3.gsub("<","<").gsub(">",">")
- "[nobbc]" + CodeRay.scan(parse, $2).div(:css => :class) + "[/nobbc]"
- end
+ def coderay(s)
+ scan=s.scan(/\[code lang=(.+?)\](.+?)\[\/code\]/m)
+ parse=scan[0][1].gsub("<","<").gsub(">",">")
+ lang=scan[0][0]
+ "[nobbc]" + CodeRay.scan(parse, lang).div(:css => :class, :line_numbers => @config[:syntax_highlighting_line_numbers]) + "[/nobbc]"
end
end
#Add .tbbc to Strings
class String