Handle stupid 0x0D bytes because browsers are stupid.

This commit is contained in:
Tom Preston-Werner
2010-07-07 17:33:04 -07:00
parent 6c7fcf89c3
commit f3cbbb8652
3 changed files with 27 additions and 3 deletions
+1 -1
View File
@@ -232,7 +232,7 @@ module Gollum
#
# Returns the placeholder'd String data.
def extract_code(data)
data.gsub(/^``` ?(.+)\n(.+)\n```$/m) do
data.gsub(/^``` ?(.+?)\r?\n(.+?)\r?\n```\r?$/m) do
id = Digest::SHA1.hexdigest($2)
@codemap[id] = { :lang => $1, :code => $2 }
id
+11 -2
View File
@@ -67,7 +67,7 @@ module Gollum
if pcommit = @repo.commit('master')
map = tree_map(pcommit.tree)
end
map[path] = data
map[path] = normalize(data)
index = tree_map_to_index(map)
parents = pcommit ? [pcommit] : []
@@ -90,7 +90,7 @@ module Gollum
pcommit = @repo.commit('master')
map = tree_map(pcommit.tree)
index = tree_map_to_index(map)
index.add(page.path, data)
index.add(page.path, normalize(data))
actor = Grit::Actor.new(commit[:name], commit[:email])
index.commit(commit[:message], [pcommit], actor)
@@ -160,6 +160,15 @@ module Gollum
# Returns the String path.
attr_reader :path
# Normalize the data.
#
# data - The String data to be normalized.
#
# Returns the normalized data String.
def normalize(data)
data.gsub(/\r/, '')
end
# Fill an array with a list of pages.
#
# tree - The Grit::Tree to start with.
+15
View File
@@ -167,6 +167,21 @@ context "Markup" do
assert_equal output, rendered
end
test "code blocks with carriage returns" do
content = "a\r\n\r\n```ruby\r\nx = 1\r\n```\r\n\r\nb"
output = "<p>a</p>\n\n<p><div class=\"highlight\"><pre>" +
"<span class=\"n\">x</span> <span class=\"o\">=</span> " +
"<span class=\"mi\">1</span>\n</pre>\n</div></p>\n\n<p>b</p>\n"
index = @wiki.repo.index
index.add("Bilbo-Baggins.md", content)
index.commit("Add alpha.jpg")
page = @wiki.page("Bilbo Baggins")
rendered = Gollum::Markup.new(page).render
assert_equal output, rendered
end
def relative_image(content, output)
index = @wiki.repo.index
index.add("greek/alpha.jpg", "hi")