mirror of
https://github.com/moparisthebest/android.moparisthebest.org
synced 2024-10-31 23:35:00 -04:00
removed some duplication in the pygments highlight method. Ensured the backtick codeblock would match newline characters in regex
This commit is contained in:
parent
0f1be647cf
commit
7224427b36
@ -11,7 +11,7 @@ module BacktickCodeBlock
|
||||
@url = nil
|
||||
@title = nil
|
||||
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 || ''
|
||||
str = $2
|
||||
|
||||
|
@ -21,11 +21,11 @@ module HighlightCode
|
||||
if File.exist?(path)
|
||||
highlighted_code = File.read(path)
|
||||
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) }
|
||||
end
|
||||
else
|
||||
highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
|
||||
highlighted_code = render(code, lang)
|
||||
end
|
||||
highlighted_code
|
||||
end
|
||||
@ -38,4 +38,8 @@ module HighlightCode
|
||||
end
|
||||
table += "</pre></td><td class='code'><pre><code class='#{lang}'>#{code}</code></pre></td></tr></table></div>"
|
||||
end
|
||||
|
||||
def render(code, lang)
|
||||
Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user