Commit 24ec186a8390080a14843c146320d1a33260789e
1 parent
6873d07f
Exists in
master
and in
4 other branches
Update Gitlab Markdown renderer to use GFM
Showing
2 changed files
with
51 additions
and
0 deletions
Show diff stats
lib/redcarpet/render/gitlab_html.rb
@@ -16,4 +16,8 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML | @@ -16,4 +16,8 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML | ||
16 | Pygments.highlight(code, :options => {:encoding => 'utf-8'}) | 16 | Pygments.highlight(code, :options => {:encoding => 'utf-8'}) |
17 | end | 17 | end |
18 | end | 18 | end |
19 | + | ||
20 | + def postprocess(full_document) | ||
21 | + h.gfm(full_document) | ||
22 | + end | ||
19 | end | 23 | end |
spec/helpers/gitlab_flavored_markdown_spec.rb
@@ -176,4 +176,51 @@ describe ApplicationHelper do | @@ -176,4 +176,51 @@ describe ApplicationHelper do | ||
176 | link_to_gfm("This should finally fix ##{issue1.id} for real", project_commit_path(@project, :id => @commit.id), :class => "foo").should have_selector(".foo") | 176 | link_to_gfm("This should finally fix ##{issue1.id} for real", project_commit_path(@project, :id => @commit.id), :class => "foo").should have_selector(".foo") |
177 | end | 177 | end |
178 | end | 178 | end |
179 | + | ||
180 | + describe "#markdown" do | ||
181 | + before do | ||
182 | + @issue = Factory :issue, :assignee => @fake_user, :author => @fake_user, :project => @project | ||
183 | + @merge_request = Factory :merge_request, :assignee => @fake_user, :author => @fake_user, :project => @project | ||
184 | + @note = Factory.create(:note, | ||
185 | + :note => "Screenshot of the new feature", | ||
186 | + :project => @project, | ||
187 | + :noteable_id => @commit.id, | ||
188 | + :noteable_type => "Commit", | ||
189 | + :attachment => "screenshot123.jpg") | ||
190 | + @snippet = Factory.create(:snippet, | ||
191 | + :title => "Render asset to string", | ||
192 | + :author => @fake_user, | ||
193 | + :project => @project) | ||
194 | + | ||
195 | + @other_user = Factory :user, name: "bill" | ||
196 | + @project.users << @other_user | ||
197 | + @member = @project.users_projects.where(:user_id => @other_user).first | ||
198 | + end | ||
199 | + | ||
200 | + it "should handle references in paragraphs" do | ||
201 | + markdown("\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. #{@commit.id} Nam pulvinar sapien eget odio adipiscing at faucibus orci vestibulum.\n").should == "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. #{link_to @commit.id, project_commit_path(@project, :id => @commit.id), :title => "Commit: #{@commit.author_name} - #{@commit.title}", :class => "gfm gfm-commit "} Nam pulvinar sapien eget odio adipiscing at faucibus orci vestibulum.</p>\n" | ||
202 | + end | ||
203 | + | ||
204 | + it "should handle references in headers" do | ||
205 | + markdown("\n# Working around ##{@issue.id} for now\n## Apply !#{@merge_request.id}").should == "<h1>Working around #{link_to "##{@issue.id}", project_issue_path(@project, @issue), :title => "Issue: #{@issue.title}", :class => "gfm gfm-issue "} for now</h1>\n\n<h2>Apply #{link_to "!#{@merge_request.id}", project_merge_request_path(@project, @merge_request), :title => "Merge Request: #{@merge_request.title}", :class => "gfm gfm-merge_request "}</h2>\n" | ||
206 | + end | ||
207 | + | ||
208 | + it "should handle references in lists" do | ||
209 | + markdown("\n* dark: ##{@issue.id}\n* light by @#{@other_user.name}\n").should == "<ul>\n<li>dark: #{link_to "##{@issue.id}", project_issue_path(@project, @issue), :title => "Issue: #{@issue.title}", :class => "gfm gfm-issue "}</li>\n<li>light by #{link_to "@#{@other_user.name}", project_team_member_path(@project, @member), :class => "gfm gfm-team_member "}</li>\n</ul>\n" | ||
210 | + end | ||
211 | + | ||
212 | + it "should handle references in <em>" do | ||
213 | + markdown("Apply _!#{@merge_request.id}_ ASAP").should == "<p>Apply <em>#{link_to "!#{@merge_request.id}", project_merge_request_path(@project, @merge_request), :title => "Merge Request: #{@merge_request.title}", :class => "gfm gfm-merge_request "}</em> ASAP</p>\n" | ||
214 | + end | ||
215 | + | ||
216 | + it "should leave code blocks untouched" do | ||
217 | + markdown("\n some code from $#{@snippet.id}\n here too\n").should == "<div class=\"highlight\"><pre><span class=\"n\">some</span> <span class=\"n\">code</span> <span class=\"n\">from</span> $#{@snippet.id}\n<span class=\"n\">here</span> <span class=\"n\">too</span>\n</pre>\n</div>\n" | ||
218 | + | ||
219 | + markdown("\n```\nsome code from $#{@snippet.id}\nhere too\n```\n").should == "<div class=\"highlight\"><pre><span class=\"n\">some</span> <span class=\"n\">code</span> <span class=\"n\">from</span> $#{@snippet.id}\n<span class=\"n\">here</span> <span class=\"n\">too</span>\n</pre>\n</div>\n" | ||
220 | + end | ||
221 | + | ||
222 | + it "should leave inline code untouched" do | ||
223 | + markdown("\nDon't use `$#{@snippet.id}` here.\n").should == "<p>Don't use <code>$#{@snippet.id}</code> here.</p>\n" | ||
224 | + end | ||
225 | + end | ||
179 | end | 226 | end |