Fix for embedding code from github
This commit is contained in:
@@ -358,9 +358,9 @@ As an extra feature, you can syntax highlight a file from your repository, allow
|
|||||||
you keep some of your sample code in the main repository. The code-snippet is
|
you keep some of your sample code in the main repository. The code-snippet is
|
||||||
updated when the wiki is rebuilt. You include github code like this:
|
updated when the wiki is rebuilt. You include github code like this:
|
||||||
|
|
||||||
```html:gollum/gollum/master/test/file_view/1_file.txt```
|
```html:github:gollum/gollum/master/test/file_view/1_file.txt```
|
||||||
|
|
||||||
This will make the builder look at the **github user**, in the **gollum project**,
|
This will make the builder look at the **gollum user**, in the **gollum project**,
|
||||||
in the **master branch**, at path **test/file_view/1_file.txt**. It will be
|
in the **master branch**, at path **test/file_view/1_file.txt**. It will be
|
||||||
rewritten to:
|
rewritten to:
|
||||||
|
|
||||||
|
|||||||
@@ -460,17 +460,17 @@ module Gollum
|
|||||||
# Acceptable formats:
|
# Acceptable formats:
|
||||||
# ```language:local-file.ext```
|
# ```language:local-file.ext```
|
||||||
# ```language:/abs/other-file.ext```
|
# ```language:/abs/other-file.ext```
|
||||||
# ```language:gollum/gollum/master/somefile.txt```
|
# ```language:github:gollum/gollum/master/somefile.txt```
|
||||||
#
|
#
|
||||||
#########################################################################
|
#########################################################################
|
||||||
|
|
||||||
def extract_gitcode data
|
def extract_gitcode data
|
||||||
data.gsub /^[ \t]*``` ?([^:\n\r]+):([^`\n\r]+)```/ do
|
data.gsub /^[ \t]*``` ?([^:\n\r]+):(?:(github:))?([^`\n\r]+)```/ do
|
||||||
contents = ''
|
contents = ''
|
||||||
# Use empty string if $2 is nil.
|
# Use empty string if $2 is nil.
|
||||||
uri = $2 || ''
|
uri = $3 || ''
|
||||||
# Detect local file.
|
# Detect local file.
|
||||||
if uri[0..6] != 'gollum/'
|
if $2.nil?
|
||||||
if file = self.find_file(uri, @wiki.ref)
|
if file = self.find_file(uri, @wiki.ref)
|
||||||
contents = file.raw_data
|
contents = file.raw_data
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -16,16 +16,18 @@ context "gitcode" do
|
|||||||
setup do
|
setup do
|
||||||
# context
|
# context
|
||||||
@wiki, @path, @cleanup = WikiFactory.create 'examples/test.git'
|
@wiki, @path, @cleanup = WikiFactory.create 'examples/test.git'
|
||||||
|
|
||||||
# given
|
|
||||||
p = page_with_content "a\n\n```html:gollum/gollum/master/test/file_view/1_file.txt```\n\nb"
|
|
||||||
|
|
||||||
# when rendering the page
|
|
||||||
@rendered = Gollum::Markup.new(p).render
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'that the rendered output is correctly fetched and rendered as html code' do
|
test 'that the rendered output is correctly fetched and rendered as html code' do
|
||||||
assert_equal %Q{<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"nt\"><ol</span> <span class=\"na\">class=</span><span class=\"s\">\"tree\"</span><span class=\"nt\">></span>\n <span class=\"nt\"><li</span> <span class=\"na\">class=</span><span class=\"s\">\"file\"</span><span class=\"nt\">></span>\n <span class=\"nt\"><a</span> <span class=\"na\">href=</span><span class=\"s\">\"0\"</span><span class=\"nt\">><span</span> <span class=\"na\">class=</span><span class=\"s\">\"icon\"</span><span class=\"nt\">></span></span>0<span class=\"nt\"></a></span>\n <span class=\"nt\"></li></span>\n<span class=\"nt\"></ol></span>\n</pre></div>\n\n<p>b</p>}, @rendered
|
# given
|
||||||
|
p = page_with_content "a\n\n```html:github:gollum/gollum/master/test/file_view/1_file.txt```\n\nb"
|
||||||
|
|
||||||
|
# when rendering the page
|
||||||
|
rendered = Gollum::Markup.new(p).render
|
||||||
|
|
||||||
|
# we expect
|
||||||
|
expected = %Q{<p>a</p>\n\n<div class=\"highlight\"><pre><span class=\"nt\"><ol</span> <span class=\"na\">class=</span><span class=\"s\">\"tree\"</span><span class=\"nt\">></span>\n <span class=\"nt\"><li</span> <span class=\"na\">class=</span><span class=\"s\">\"file\"</span><span class=\"nt\">></span>\n <span class=\"nt\"><a</span> <span class=\"na\">href=</span><span class=\"s\">\"0\"</span><span class=\"nt\">><span</span> <span class=\"na\">class=</span><span class=\"s\">\"icon\"</span><span class=\"nt\">></span></span>0<span class=\"nt\"></a></span>\n <span class=\"nt\"></li></span>\n<span class=\"nt\"></ol></span>\n</pre></div>\n\n<p>b</p>}
|
||||||
|
assert_equal expected, rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'contents' do
|
test 'contents' do
|
||||||
|
|||||||
Reference in New Issue
Block a user