use Albino::Multi
This commit is contained in:
+11
-6
@@ -1,12 +1,17 @@
|
|||||||
require 'albino'
|
require 'albino/multi'
|
||||||
|
|
||||||
class Gollum::Albino < Albino
|
class Gollum::Albino < Albino::Multi
|
||||||
self.bin = ::Albino.bin
|
self.bin = ::Albino::Multi.bin
|
||||||
self.default_encoding = ::Albino.default_encoding
|
|
||||||
|
|
||||||
def colorize(options = {})
|
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.sub!(%r{</pre></div>\Z}, "</pre>\n</div>")
|
||||||
html
|
html
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+29
-16
@@ -380,26 +380,39 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# Returns the marked up String data.
|
# Returns the marked up String data.
|
||||||
def process_code(data)
|
def process_code(data)
|
||||||
|
return data if data.nil? || data.size.zero? || @codemap.size.zero?
|
||||||
|
|
||||||
|
blocks = []
|
||||||
@codemap.each do |id, spec|
|
@codemap.each do |id, spec|
|
||||||
formatted = spec[:output] || begin
|
next if spec[:output] # cached
|
||||||
code = spec[:code]
|
|
||||||
lang = spec[:lang]
|
|
||||||
|
|
||||||
if code.lines.all? { |line| line =~ /\A\r?\n\Z/ || line =~ /^( |\t)/ }
|
code = spec[:code]
|
||||||
code.gsub!(/^( |\t)/m, '')
|
if code.lines.all? { |line| line =~ /\A\r?\n\Z/ || line =~ /^( |\t)/ }
|
||||||
end
|
code.gsub!(/^( |\t)/m, '')
|
||||||
|
|
||||||
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
|
|
||||||
end
|
end
|
||||||
data.gsub!(id, formatted)
|
|
||||||
|
blocks << [spec[:lang], code]
|
||||||
end
|
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
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -422,18 +422,6 @@ context "Markup" do
|
|||||||
compare(content, output)
|
compare(content, output)
|
||||||
end
|
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<booya></code></pre>\n\n<p>b</p>"
|
|
||||||
compare(content, output)
|
|
||||||
end
|
|
||||||
|
|
||||||
#########################################################################
|
#########################################################################
|
||||||
#
|
#
|
||||||
# Various
|
# Various
|
||||||
|
|||||||
Reference in New Issue
Block a user