diff --git a/plugins/code_block.rb b/plugins/code_block.rb
index ff242aa..55267a3 100644
--- a/plugins/code_block.rb
+++ b/plugins/code_block.rb
@@ -64,7 +64,7 @@ module Jekyll
@file = $1
@caption = "
" + code.lstrip.rstrip.gsub(/,'<') + "
"
+ source += "#{tableize_code(code.lstrip.rstrip.gsub(/,'<'))}"
end
source = source + context['pygments_suffix'] if context['pygments_suffix']
end
diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb
index 9c94f0e..1170f8b 100644
--- a/plugins/octopress_filters.rb
+++ b/plugins/octopress_filters.rb
@@ -26,14 +26,17 @@ module OctopressFilters
# code snippet
# ```
def backtick_codeblock(input)
+ code = nil
# Markdown support
input = input.gsub /`{3}\s*(\w+)?<\/p>\s*
\s*(.+?)\s*<\/code><\/pre>\s*`{3}<\/p>/m do
lang = $1
if lang != ''
str = $2.gsub('<','<').gsub('>','>').gsub('&','&')
- highlight(str, lang)
+ code = highlight(str, lang)
+ ""
else
- "
#{$2}
"
+ code = tableize_code($2)
+ ""
end
end
@@ -48,9 +51,11 @@ module OctopressFilters
lang = $1
str = $2.gsub(/^\s{4}/, '')
if lang != ''
- highlight(str, lang)
+ code = highlight(str, lang)
+ ""
else
- "#{$2.gsub('<','<').gsub('>','>')}
"
+ code = tableize_code($2.gsub('<','<').gsub('>','>'))
+ ""
end
end
end
diff --git a/plugins/pygments_code.rb b/plugins/pygments_code.rb
index cdd6c3a..1930ec8 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