Commit 539b4192 authored by Douwe Maan's avatar Douwe Maan

Milestone reference is a Markdown link

parent b38eabda
...@@ -71,8 +71,12 @@ class Milestone < ActiveRecord::Base ...@@ -71,8 +71,12 @@ class Milestone < ActiveRecord::Base
end end
def to_reference(from_project = nil) def to_reference(from_project = nil)
escaped_title = self.title.gsub("]", "\\]")
h = Gitlab::Application.routes.url_helpers h = Gitlab::Application.routes.url_helpers
h.namespace_project_milestone_url(self.project.namespace, self.project, self) url = h.namespace_project_milestone_url(self.project.namespace, self.project, self)
"[#{escaped_title}](#{url})"
end end
def reference_link_text(from_project = nil) def reference_link_text(from_project = nil)
......
...@@ -219,7 +219,6 @@ References should be parseable even inside _<%= merge_request.to_reference %>_ e ...@@ -219,7 +219,6 @@ References should be parseable even inside _<%= merge_request.to_reference %>_ e
- Milestone: <%= milestone.to_reference %> - Milestone: <%= milestone.to_reference %>
- Milestone in another project: <%= xmilestone.to_reference(project) %> - Milestone in another project: <%= xmilestone.to_reference(project) %>
- Ignored in code: `<%= milestone.to_reference %>` - Ignored in code: `<%= milestone.to_reference %>`
- Ignored in links: [Link to <%= milestone.to_reference %>](#milestone-link)
- Link to milestone by URL: [Milestone](<%= urls.namespace_project_milestone_url(milestone.project.namespace, milestone.project, milestone) %>) - Link to milestone by URL: [Milestone](<%= urls.namespace_project_milestone_url(milestone.project.namespace, milestone.project, milestone) %>)
### Task Lists ### Task Lists
......
...@@ -18,7 +18,9 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do ...@@ -18,7 +18,9 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do
end end
context 'internal reference' do context 'internal reference' do
let(:reference) { milestone.to_reference } # Convert the Markdown link to only the URL, since these tests aren't run through the regular Markdown pipeline.
# Milestone reference behavior in the full Markdown pipeline is tested elsewhere.
let(:reference) { milestone.to_reference.gsub(/\[([^\]]+)\]\(([^)]+)\)/, '\2') }
it 'links to a valid reference' do it 'links to a valid reference' do
doc = reference_filter("See #{reference}") doc = reference_filter("See #{reference}")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment