From 24ec186a8390080a14843c146320d1a33260789e Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Thu, 2 Aug 2012 02:29:15 +0200 Subject: [PATCH] Update Gitlab Markdown renderer to use GFM --- lib/redcarpet/render/gitlab_html.rb | 4 ++ spec/helpers/gitlab_flavored_markdown_spec.rb | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/lib/redcarpet/render/gitlab_html.rb b/lib/redcarpet/render/gitlab_html.rb index 6530adf0..33403ded 100644 --- a/lib/redcarpet/render/gitlab_html.rb +++ b/lib/redcarpet/render/gitlab_html.rb @@ -16,4 +16,8 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML Pygments.highlight(code, :options => {:encoding => 'utf-8'}) end end + + def postprocess(full_document) + h.gfm(full_document) + end end diff --git a/spec/helpers/gitlab_flavored_markdown_spec.rb b/spec/helpers/gitlab_flavored_markdown_spec.rb index f64362fa..aeace00c 100644 --- a/spec/helpers/gitlab_flavored_markdown_spec.rb +++ b/spec/helpers/gitlab_flavored_markdown_spec.rb @@ -176,4 +176,51 @@ describe ApplicationHelper do link_to_gfm("This should finally fix ##{issue1.id} for real", project_commit_path(@project, :id => @commit.id), :class => "foo").should have_selector(".foo") end end + + describe "#markdown" do + before do + @issue = Factory :issue, :assignee => @fake_user, :author => @fake_user, :project => @project + @merge_request = Factory :merge_request, :assignee => @fake_user, :author => @fake_user, :project => @project + @note = Factory.create(:note, + :note => "Screenshot of the new feature", + :project => @project, + :noteable_id => @commit.id, + :noteable_type => "Commit", + :attachment => "screenshot123.jpg") + @snippet = Factory.create(:snippet, + :title => "Render asset to string", + :author => @fake_user, + :project => @project) + + @other_user = Factory :user, name: "bill" + @project.users << @other_user + @member = @project.users_projects.where(:user_id => @other_user).first + end + + it "should handle references in paragraphs" do + markdown("\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. #{@commit.id} Nam pulvinar sapien eget odio adipiscing at faucibus orci vestibulum.\n").should == "

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.

\n" + end + + it "should handle references in headers" do + markdown("\n# Working around ##{@issue.id} for now\n## Apply !#{@merge_request.id}").should == "

Working around #{link_to "##{@issue.id}", project_issue_path(@project, @issue), :title => "Issue: #{@issue.title}", :class => "gfm gfm-issue "} for now

\n\n

Apply #{link_to "!#{@merge_request.id}", project_merge_request_path(@project, @merge_request), :title => "Merge Request: #{@merge_request.title}", :class => "gfm gfm-merge_request "}

\n" + end + + it "should handle references in lists" do + markdown("\n* dark: ##{@issue.id}\n* light by @#{@other_user.name}\n").should == "\n" + end + + it "should handle references in " do + markdown("Apply _!#{@merge_request.id}_ ASAP").should == "

Apply #{link_to "!#{@merge_request.id}", project_merge_request_path(@project, @merge_request), :title => "Merge Request: #{@merge_request.title}", :class => "gfm gfm-merge_request "} ASAP

\n" + end + + it "should leave code blocks untouched" do + markdown("\n some code from $#{@snippet.id}\n here too\n").should == "
some code from $#{@snippet.id}\nhere too\n
\n
\n" + + markdown("\n```\nsome code from $#{@snippet.id}\nhere too\n```\n").should == "
some code from $#{@snippet.id}\nhere too\n
\n
\n" + end + + it "should leave inline code untouched" do + markdown("\nDon't use `$#{@snippet.id}` here.\n").should == "

Don't use $#{@snippet.id} here.

\n" + end + end end