diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb index b7fec9fc1d9..924e6cb1979 100644 --- a/app/helpers/gitlab_markdown_helper.rb +++ b/app/helpers/gitlab_markdown_helper.rb @@ -38,6 +38,11 @@ module GitlabMarkdownHelper end end + # Add any custom CSS classes to the GFM-generated reference links + if html_options[:class] + fragment.css('a.gfm').add_class(html_options[:class]) + end + fragment.to_html.html_safe end diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index d1ca2337a9b..0f9c587432d 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -79,6 +79,16 @@ describe GitlabMarkdownHelper do expect(doc.css('a')[4].text).to eq ' for real' end + it 'should forward HTML options' do + actual = link_to_gfm("Fixed in #{commit.id}", commit_path, class: 'foo') + doc = Nokogiri::HTML.parse(actual) + + expect(doc.css('a')).to satisfy do |v| + # 'foo' gets added to all links + v.all? { |a| a.attr('class').match(/foo$/) } + end + end + it "escapes HTML passed in as the body" do actual = "This is a

test

- see #{issues[0].to_reference}" expect(link_to_gfm(actual, commit_path)).