From ef4a42f9774ca36c8cf9921aadda93572c26fba6 Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Tue, 16 Aug 2011 02:40:47 -0400 Subject: Codeblock regex improved to better detect extensions fixes #96, added support for tableizing non highlighted code blocks from liquid codeblock tag and backtick code blocks --- plugins/pygments_code.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'plugins/pygments_code.rb') diff --git a/plugins/pygments_code.rb b/plugins/pygments_code.rb index cdd6c3a4..1930ec83 100644 --- a/plugins/pygments_code.rb +++ b/plugins/pygments_code.rb @@ -8,13 +8,7 @@ FileUtils.mkdir_p(PYGMENTS_CACHE_DIR) module HighlightCode def highlight(str, lang) str = pygments(str, lang).match(/
(.+)<\/pre>/m)[1].to_s.gsub(/ *$/, '') #strip out divs 
- table = '
'
-    code = ''
-    str.lines.each_with_index do |line,index|
-      table += "#{index+1}\n"
-      code  += "
#{line}
" - end - table += "
#{code}
" + tableize_code(str, lang) end def pygments(code, lang) @@ -31,4 +25,13 @@ module HighlightCode end highlighted_code end + def tableize_code (str, lang = '') + table = '
'
+    code = ''
+    str.lines.each_with_index do |line,index|
+      table += "#{index+1}\n"
+      code  += "
#{line}
" + end + table += "
#{code}
" + end end -- cgit v1.2.1