aboutsummaryrefslogtreecommitdiff
path: root/plugins/pygments_code.rb
diff options
context:
space:
mode:
authorBrandon Mathis <brandon@imathis.com>2011-08-16 02:40:47 -0400
committerBrandon Mathis <brandon@imathis.com>2011-08-16 02:41:28 -0400
commitef4a42f9774ca36c8cf9921aadda93572c26fba6 (patch)
treea1376cabeea8613f1a0ff4200d5f5a67c0e903d9 /plugins/pygments_code.rb
parent59521e3db81b36f8abe8c61802f5acf74d15ebfe (diff)
downloadmy_new_personal_website-ef4a42f9774ca36c8cf9921aadda93572c26fba6.tar.xz
my_new_personal_website-ef4a42f9774ca36c8cf9921aadda93572c26fba6.zip
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
Diffstat (limited to '')
-rw-r--r--plugins/pygments_code.rb17
1 files changed, 10 insertions, 7 deletions
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>(.+)<\/pre>/m)[1].to_s.gsub(/ *$/, '') #strip out divs <div class="highlight">
- table = '<div class="highlight"><table cellpadding="0" cellspacing="0"><tr><td class="gutter"><pre class="line-numbers">'
- code = ''
- str.lines.each_with_index do |line,index|
- table += "<span class='line'>#{index+1}</span>\n"
- code += "<div class='line'>#{line}</div>"
- end
- table += "</pre></td><td class='code' width='100%'><pre><code class='#{lang}'>#{code}</code></pre></td></tr></table></div>"
+ 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 = '<div class="highlight"><table cellpadding="0" cellspacing="0"><tr><td class="gutter"><pre class="line-numbers">'
+ code = ''
+ str.lines.each_with_index do |line,index|
+ table += "<span class='line'>#{index+1}</span>\n"
+ code += "<div class='line'>#{line}</div>"
+ end
+ table += "</pre></td><td class='code' width='100%'><pre><code class='#{lang}'>#{code}</code></pre></td></tr></table></div>"
+ end
end