Commit 9c6f4a23 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'dashboard-references' into 'master'

Fix reference links in dashboard activity and ATOM feeds.

References like `@user` were not linked on the dashboard activity feed and in Atom feeds, because the reference parser depends on `@project` which isn't set in those situations.

This MR passes the project in question to the reference parsers in an option.

cc @rspeicher

See merge request !653
parents de1aca13 cd52cef1
...@@ -65,6 +65,7 @@ v 7.11.0 (unreleased) ...@@ -65,6 +65,7 @@ v 7.11.0 (unreleased)
- Fix mentioning of private groups. - Fix mentioning of private groups.
- Add style for <kbd> element in markdown - Add style for <kbd> element in markdown
- Spin spinner icon next to "Checking for CI status..." on MR page. - Spin spinner icon next to "Checking for CI status..." on MR page.
- Fix reference links in dashboard activity and ATOM feeds.
v 7.10.2 v 7.10.2
- Fix CI links on MR page - Fix CI links on MR page
......
...@@ -168,8 +168,8 @@ module EventsHelper ...@@ -168,8 +168,8 @@ module EventsHelper
end end
end end
def event_note(text) def event_note(text, options = {})
text = first_line_in_markdown(text, 150) text = first_line_in_markdown(text, 150, options)
sanitize(text, tags: %w(a img b pre code p span)) sanitize(text, tags: %w(a img b pre code p span))
end end
......
...@@ -19,7 +19,7 @@ module GitlabMarkdownHelper ...@@ -19,7 +19,7 @@ module GitlabMarkdownHelper
escape_once(body) escape_once(body)
end end
gfm_body = gfm(escaped_body, @project, html_options) gfm_body = gfm(escaped_body, {}, html_options)
gfm_body.gsub!(%r{<a.*?>.*?</a>}m) do |match| gfm_body.gsub!(%r{<a.*?>.*?</a>}m) do |match|
"</a>#{match}#{link_to("", url, html_options)[0..-5]}" # "</a>".length +1 "</a>#{match}#{link_to("", url, html_options)[0..-5]}" # "</a>".length +1
...@@ -32,11 +32,13 @@ module GitlabMarkdownHelper ...@@ -32,11 +32,13 @@ module GitlabMarkdownHelper
unless @markdown && options == @options unless @markdown && options == @options
@options = options @options = options
# see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch options.merge!(
rend = Redcarpet::Render::GitlabHTML.new(self, user_color_scheme_class, {
# Handled further down the line by Gitlab::Markdown::SanitizationFilter # Handled further down the line by Gitlab::Markdown::SanitizationFilter
escape_html: false escape_html: false
}.merge(options)) )
# see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch
rend = Redcarpet::Render::GitlabHTML.new(self, user_color_scheme_class, options)
# see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use # see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use
@markdown = Redcarpet::Markdown.new(rend, @markdown = Redcarpet::Markdown.new(rend,
...@@ -58,8 +60,8 @@ module GitlabMarkdownHelper ...@@ -58,8 +60,8 @@ module GitlabMarkdownHelper
# as Markdown. HTML tags in the parsed output are not counted toward the # as Markdown. HTML tags in the parsed output are not counted toward the
# +max_chars+ limit. If the length limit falls within a tag's contents, then # +max_chars+ limit. If the length limit falls within a tag's contents, then
# the tag contents are truncated without removing the closing tag. # the tag contents are truncated without removing the closing tag.
def first_line_in_markdown(text, max_chars = nil) def first_line_in_markdown(text, max_chars = nil, options = {})
md = markdown(text).strip md = markdown(text, options).strip
truncate_visible(md, max_chars || md.length) if md.present? truncate_visible(md, max_chars || md.length) if md.present?
end end
......
%div{xmlns: "http://www.w3.org/1999/xhtml"} %div{xmlns: "http://www.w3.org/1999/xhtml"}
- if issue.description.present? - if issue.description.present?
= markdown(issue.description, xhtml: true) = markdown(issue.description, xhtml: true, reference_only_path: false, project: issue.project)
%div{xmlns: "http://www.w3.org/1999/xhtml"} %div{xmlns: "http://www.w3.org/1999/xhtml"}
- if merge_request.description.present? - if merge_request.description.present?
= markdown(merge_request.description, xhtml: true) = markdown(merge_request.description, xhtml: true, reference_only_path: false, project: merge_request.project)
%div{xmlns: "http://www.w3.org/1999/xhtml"} %div{xmlns: "http://www.w3.org/1999/xhtml"}
= markdown(note.note, xhtml: true) = markdown(note.note, xhtml: true, reference_only_path: false, project: note.project)
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
%i %i
at at
= commit[:timestamp].to_time.to_s(:short) = commit[:timestamp].to_time.to_s(:short)
%blockquote= markdown(escape_once(commit[:message]), xhtml: true) %blockquote= markdown(escape_once(commit[:message]), xhtml: true, reference_only_path: false, project: note.project)
- if event.commits_count > 15 - if event.commits_count > 15
%p %p
%i %i
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
.event-note .event-note
.md .md
%i.fa.fa-comment-o.event-note-icon %i.fa.fa-comment-o.event-note-icon
= event_note(event.target.note) = event_note(event.target.note, project: event.project)
- note = event.target - note = event.target
- if note.attachment.url - if note.attachment.url
- if note.attachment.image? - if note.attachment.image?
......
...@@ -24,10 +24,10 @@ module Gitlab ...@@ -24,10 +24,10 @@ module Gitlab
# Public: Parse the provided text with GitLab-Flavored Markdown # Public: Parse the provided text with GitLab-Flavored Markdown
# #
# text - the source text # text - the source text
# project - the project # options - options
# html_options - extra options for the reference links as given to link_to # html_options - extra options for the reference links as given to link_to
def gfm(text, project = @project, html_options = {}) def gfm(text, options = {}, html_options = {})
gfm_with_options(text, {}, project, html_options) gfm_with_options(text, options, html_options)
end end
# Public: Parse the provided text with GitLab-Flavored Markdown # Public: Parse the provided text with GitLab-Flavored Markdown
...@@ -38,7 +38,7 @@ module Gitlab ...@@ -38,7 +38,7 @@ module Gitlab
# :reference_only_path - Use relative path for reference links # :reference_only_path - Use relative path for reference links
# project - the project # project - the project
# html_options - extra options for the reference links as given to link_to # html_options - extra options for the reference links as given to link_to
def gfm_with_options(text, options = {}, project = @project, html_options = {}) def gfm_with_options(text, options = {}, html_options = {})
return text if text.nil? return text if text.nil?
# Duplicate the string so we don't alter the original, then call to_str # Duplicate the string so we don't alter the original, then call to_str
...@@ -48,7 +48,9 @@ module Gitlab ...@@ -48,7 +48,9 @@ module Gitlab
options.reverse_merge!( options.reverse_merge!(
xhtml: false, xhtml: false,
reference_only_path: true reference_only_path: true,
project: @project,
current_user: current_user
) )
pipeline = HTML::Pipeline.new(filters) pipeline = HTML::Pipeline.new(filters)
...@@ -62,9 +64,9 @@ module Gitlab ...@@ -62,9 +64,9 @@ module Gitlab
no_header_anchors: options[:no_header_anchors], no_header_anchors: options[:no_header_anchors],
# ReferenceFilter # ReferenceFilter
current_user: current_user, current_user: options[:current_user],
only_path: options[:reference_only_path], only_path: options[:reference_only_path],
project: project, project: options[:project],
reference_class: html_options[:class], reference_class: html_options[:class],
# RelativeLinkFilter # RelativeLinkFilter
......
...@@ -7,9 +7,12 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML ...@@ -7,9 +7,12 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
def initialize(template, color_scheme, options = {}) def initialize(template, color_scheme, options = {})
@template = template @template = template
@color_scheme = color_scheme @color_scheme = color_scheme
@project = @template.instance_variable_get("@project")
@options = options.dup @options = options.dup
@options.reverse_merge!(
project: @template.instance_variable_get("@project")
)
super(options) super(options)
end end
......
...@@ -21,7 +21,7 @@ describe GitlabMarkdownHelper do ...@@ -21,7 +21,7 @@ describe GitlabMarkdownHelper do
describe "#gfm" do describe "#gfm" do
it "should forward HTML options to links" do it "should forward HTML options to links" do
expect(gfm("Fixed in #{commit.id}", @project, class: 'foo')). expect(gfm("Fixed in #{commit.id}", { project: @project }, class: 'foo')).
to have_selector('a.gfm.foo') to have_selector('a.gfm.foo')
end end
......
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