tweak code markup parser so that blocks without a language are just output in pre tags
This commit is contained in:
@@ -359,7 +359,7 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# Returns the placeholder'd String data.
|
# Returns the placeholder'd String data.
|
||||||
def extract_code(data)
|
def extract_code(data)
|
||||||
data.gsub!(/^``` ?(.+?)\r?\n(.+?)\r?\n```\r?$/m) do
|
data.gsub!(/^``` ?([^\r\n]+)?\r?\n(.+?)\r?\n```\r?$/m) do
|
||||||
id = Digest::SHA1.hexdigest($2)
|
id = Digest::SHA1.hexdigest($2)
|
||||||
cached = check_cache(:code, id)
|
cached = check_cache(:code, id)
|
||||||
@codemap[id] = cached ?
|
@codemap[id] = cached ?
|
||||||
@@ -379,12 +379,15 @@ module Gollum
|
|||||||
def process_code(data)
|
def process_code(data)
|
||||||
@codemap.each do |id, spec|
|
@codemap.each do |id, spec|
|
||||||
formatted = spec[:output] || begin
|
formatted = spec[:output] || begin
|
||||||
lang = spec[:lang]
|
|
||||||
code = spec[:code]
|
code = spec[:code]
|
||||||
if code.lines.all? { |line| line =~ /\A\r?\n\Z/ || line =~ /^( |\t)/ }
|
if code.lines.all? { |line| line =~ /\A\r?\n\Z/ || line =~ /^( |\t)/ }
|
||||||
code.gsub!(/^( |\t)/m, '')
|
code.gsub!(/^( |\t)/m, '')
|
||||||
end
|
end
|
||||||
formatted = Gollum::Albino.new(code, lang).colorize
|
formatted = if lang = spec[:lang]
|
||||||
|
Gollum::Albino.new(code, lang).colorize
|
||||||
|
else
|
||||||
|
"<pre><code>#{CGI.escapeHTML(code)}</code></pre>"
|
||||||
|
end
|
||||||
update_cache(:code, id, formatted)
|
update_cache(:code, id, formatted)
|
||||||
formatted
|
formatted
|
||||||
end
|
end
|
||||||
|
|||||||
+2
-2
@@ -394,8 +394,8 @@ context "Markup" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "code block with no lang" do
|
test "code block with no lang" do
|
||||||
content = "a\n\n```\n\tls -al;\n\tbooya\n```\n\nb"
|
content = "a\n\n```\n\tls -al;\n\t<booya>\n```\n\nb"
|
||||||
output = "<p>a</p>\n\n\n\n<p>b</p>"
|
output = "<p>a</p>\n\n<pre><code>ls -al;\n<booya></code></pre>\n\n<p>b</p>"
|
||||||
compare(content, output)
|
compare(content, output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user