removed some duplication in the pygments highlight method. Ensured the backtick codeblock would match newline characters in regex

This commit is contained in:
Brandon Mathis 2012-05-21 23:59:49 -05:00
parent 0f1be647cf
commit 7224427b36
2 changed files with 7 additions and 3 deletions

View File

@ -11,7 +11,7 @@ module BacktickCodeBlock
@url = nil @url = nil
@title = nil @title = nil
input.encode!("UTF-8") input.encode!("UTF-8")
input.gsub(/^`{3} *([^\n]+)?\n(.+?)\n`{3}/m) do input.gsub(/^`{3} *([^\n]+)?\n([\S\s]+?)\n`{3}/m) do
@options = $1 || '' @options = $1 || ''
str = $2 str = $2

View File

@ -21,11 +21,11 @@ module HighlightCode
if File.exist?(path) if File.exist?(path)
highlighted_code = File.read(path) highlighted_code = File.read(path)
else else
highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'}) highlighted_code = render(code, lang)
File.open(path, 'w') {|f| f.print(highlighted_code) } File.open(path, 'w') {|f| f.print(highlighted_code) }
end end
else else
highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'}) highlighted_code = render(code, lang)
end end
highlighted_code highlighted_code
end end
@ -38,4 +38,8 @@ module HighlightCode
end end
table += "</pre></td><td class='code'><pre><code class='#{lang}'>#{code}</code></pre></td></tr></table></div>" table += "</pre></td><td class='code'><pre><code class='#{lang}'>#{code}</code></pre></td></tr></table></div>"
end end
def render(code, lang)
Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
end
end end