Commit 7665b1de7eed4addd7b94786c84e6674710e6377

Authored by Dan Knox
1 parent f0aa54e0

Use Gitlab Markdown for Markdown files and Gollum to render the rest.

This commit enables the usage of the Gitlab Markdown post processing
on all Markdown formatted files. For file types that do not contain
Markdown, it defaults to the Gollum native renderer to process the
content.
app/helpers/gitlab_markdown_helper.rb
... ... @@ -49,4 +49,12 @@ module GitlabMarkdownHelper
49 49  
50 50 @markdown.render(text).html_safe
51 51 end
  52 +
  53 + def render_wiki_content(wiki_page)
  54 + if wiki_page.format == :markdown
  55 + markdown(wiki_page.content)
  56 + else
  57 + wiki_page.formatted_content.html_safe
  58 + end
  59 + end
52 60 end
... ...
app/views/wikis/show.html.haml
... ... @@ -10,7 +10,7 @@
10 10 .file_holder
11 11 .file_content.wiki
12 12 = preserve do
13   - = @wiki.formatted_content.html_safe
  13 + = render_wiki_content(@wiki)
14 14  
15 15 - commit = CommitDecorator.new(@wiki.version)
16 16 %p.time Last edited by #{commit.author_link(avatar: true, size: 16)} #{time_ago_in_words @wiki.created_at} ago
... ...
spec/helpers/gitlab_markdown_helper_spec.rb
... ... @@ -363,4 +363,28 @@ describe GitlabMarkdownHelper do
363 363 markdown(":smile:").should include("src=\"#{url_to_image("emoji/smile")}")
364 364 end
365 365 end
  366 +
  367 + describe "#render_wiki_content" do
  368 + before do
  369 + @wiki = stub('WikiPage')
  370 + @wiki.stub(:content).and_return('wiki content')
  371 + end
  372 +
  373 + it "should use Gitlab Flavored Markdown for markdown files" do
  374 + @wiki.stub(:format).and_return(:markdown)
  375 +
  376 + helper.should_receive(:markdown).with('wiki content')
  377 +
  378 + helper.render_wiki_content(@wiki)
  379 + end
  380 +
  381 + it "should use the Gollum renderer for all other file types" do
  382 + @wiki.stub(:format).and_return(:rdoc)
  383 + formatted_content_stub = stub('formatted_content')
  384 + formatted_content_stub.should_receive(:html_safe)
  385 + @wiki.stub(:formatted_content).and_return(formatted_content_stub)
  386 +
  387 + helper.render_wiki_content(@wiki)
  388 + end
  389 + end
366 390 end
... ...