use Albino::Multi

This commit is contained in:
rick
2011-03-03 16:28:13 -08:00
parent 83c0dbaaf2
commit ecb44b50e1
3 changed files with 40 additions and 34 deletions
+11 -6
View File
@@ -1,12 +1,17 @@
require 'albino'
require 'albino/multi'
class Gollum::Albino < Albino
self.bin = ::Albino.bin
self.default_encoding = ::Albino.default_encoding
class Gollum::Albino < Albino::Multi
self.bin = ::Albino::Multi.bin
def colorize(options = {})
html = super.to_s
case out = super
when Array then out.each { |s| fix_html(s) }
else fix_html(out)
end
end
def fix_html(html)
html.sub!(%r{</pre></div>\Z}, "</pre>\n</div>")
html
end
end
end
+29 -16
View File
@@ -380,26 +380,39 @@ module Gollum
#
# Returns the marked up String data.
def process_code(data)
return data if data.nil? || data.size.zero? || @codemap.size.zero?
blocks = []
@codemap.each do |id, spec|
formatted = spec[:output] || begin
code = spec[:code]
lang = spec[:lang]
next if spec[:output] # cached
if code.lines.all? { |line| line =~ /\A\r?\n\Z/ || line =~ /^( |\t)/ }
code.gsub!(/^( |\t)/m, '')
end
formatted = begin
lang && Gollum::Albino.colorize(code, lang)
rescue ::Albino::ShellArgumentError, ::POSIX::Spawn::TimeoutExceeded,
::POSIX::Spawn::MaximumOutputExceeded
end
formatted ||= "<pre><code>#{CGI.escapeHTML(code)}</code></pre>"
update_cache(:code, id, formatted)
formatted
code = spec[:code]
if code.lines.all? { |line| line =~ /\A\r?\n\Z/ || line =~ /^( |\t)/ }
code.gsub!(/^( |\t)/m, '')
end
data.gsub!(id, formatted)
blocks << [spec[:lang], code]
end
highlighted = begin
blocks.size.zero? ? [] : Gollum::Albino.colorize(blocks)
rescue ::Albino::ShellArgumentError, ::POSIX::Spawn::TimeoutExceeded,
::POSIX::Spawn::MaximumOutputExceeded
[]
end
@codemap.each do |id, spec|
body = spec[:output] || begin
if (body = highlighted.shift.to_s).size > 0
update_cache(:code, id, body)
body
else
"<pre><code>#{CGI.escapeHTML(spec[:code])}</code></pre>"
end
end
data.gsub!(id, body)
end
data
end
-12
View File
@@ -422,18 +422,6 @@ context "Markup" do
compare(content, output)
end
test "code block with invalid lang" do
content = "a\n\n``` ls -al;\n\tbooya\n\tboom\n```\n\nb"
output = "<p>a</p>\n\n<pre><code>booya\nboom</code></pre>\n\n<p>b</p>"
compare(content, output)
end
test "code block with no lang" do
content = "a\n\n```\n\tls -al;\n\t<booya>\n```\n\nb"
output = "<p>a</p>\n\n<pre><code>ls -al;\n&lt;booya&gt;</code></pre>\n\n<p>b</p>"
compare(content, output)
end
#########################################################################
#
# Various