Fix parsing extra whitespace in code blocks
This commit is contained in:
@@ -459,11 +459,12 @@ module Gollum
|
|||||||
# Returns the placeholder'd String data.
|
# Returns the placeholder'd String data.
|
||||||
def extract_code(data)
|
def extract_code(data)
|
||||||
data.gsub!(/^([ \t]*)``` ?([^\r\n]+)?\r?\n(.+?)\r?\n\1```\r?$/m) do
|
data.gsub!(/^([ \t]*)``` ?([^\r\n]+)?\r?\n(.+?)\r?\n\1```\r?$/m) do
|
||||||
id = Digest::SHA1.hexdigest("#{$2}.#{$3}")
|
lang = $2 ? $2.strip : nil
|
||||||
|
id = Digest::SHA1.hexdigest("#{lang}.#{$3}")
|
||||||
cached = check_cache(:code, id)
|
cached = check_cache(:code, id)
|
||||||
@codemap[id] = cached ?
|
@codemap[id] = cached ?
|
||||||
{ :output => cached } :
|
{ :output => cached } :
|
||||||
{ :lang => $2, :code => $3, :indent => $1 }
|
{ :lang => lang, :code => $3, :indent => $1 }
|
||||||
"#{$1}#{id}" # print the SHA1 ID with the proper indentation
|
"#{$1}#{id}" # print the SHA1 ID with the proper indentation
|
||||||
end
|
end
|
||||||
data
|
data
|
||||||
|
|||||||
@@ -468,6 +468,20 @@ context "Markup" do
|
|||||||
content = <<-END
|
content = <<-END
|
||||||
booya
|
booya
|
||||||
|
|
||||||
|
``` python
|
||||||
|
np.array([[2,2],[1,3]],np.float)
|
||||||
|
```
|
||||||
|
END
|
||||||
|
|
||||||
|
# rendered with Gollum::Markup
|
||||||
|
page, rendered = render_page(content)
|
||||||
|
assert_markup_highlights_code Gollum::Markup, rendered
|
||||||
|
end
|
||||||
|
|
||||||
|
test "code with trailing whitespace" do
|
||||||
|
content = <<-END
|
||||||
|
shoop da woop
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
np.array([[2,2],[1,3]],np.float)
|
np.array([[2,2],[1,3]],np.float)
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user