Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/markdown/abstract_reference_filter.rb')
-rw-r--r--lib/gitlab/markdown/abstract_reference_filter.rb20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/gitlab/markdown/abstract_reference_filter.rb b/lib/gitlab/markdown/abstract_reference_filter.rb
index f6df9518fc6..37ed423eeda 100644
--- a/lib/gitlab/markdown/abstract_reference_filter.rb
+++ b/lib/gitlab/markdown/abstract_reference_filter.rb
@@ -37,8 +37,8 @@ module Gitlab
# of the external project reference, and all of the matchdata.
#
# Returns a String replaced with the return of the block.
- def self.references_in(text)
- text.gsub(object_class.reference_pattern) do |match|
+ def self.references_in(text, pattern = object_class.reference_pattern)
+ text.gsub(pattern) do |match|
yield match, $~[object_sym].to_i, $~[:project], $~
end
end
@@ -61,7 +61,11 @@ module Gitlab
def call
replace_text_nodes_matching(object_class.reference_pattern) do |content|
- object_link_filter(content)
+ object_link_filter(content, object_class.reference_pattern)
+ end
+
+ replace_link_nodes_matching(object_class.link_reference_pattern) do |content|
+ object_link_filter(content, object_class.link_reference_pattern)
end
end
@@ -72,15 +76,17 @@ module Gitlab
#
# Returns a String with references replaced with links. All links
# have `gfm` and `gfm-OBJECT_NAME` class names attached for styling.
- def object_link_filter(text)
- references_in(text) do |match, id, project_ref, matches|
+ def object_link_filter(text, pattern)
+ references_in(text, pattern) do |match, id, project_ref, matches|
project = project_from_ref(project_ref)
if project && object = find_object(project, id)
title = escape_once(object_link_title(object))
klass = reference_class(object_sym)
data = data_attribute(project: project.id, object_sym => object.id, original: match)
- url = matches[:url] || url_for_object(object, project)
+
+ url = matches[:url] if matches.names.include?("url")
+ url ||= url_for_object(object, project)
text = object.reference_link_text(context[:project])
@@ -99,7 +105,7 @@ module Gitlab
def object_link_text_extras(object, matches)
extras = []
- if matches[:anchor] && matches[:anchor] =~ /\A\#note_(\d+)\z/
+ if matches.names.include?("anchor") && matches[:anchor] && matches[:anchor] =~ /\A\#note_(\d+)\z/
extras << "comment #{$1}"
end