summaryrefslogtreecommitdiff
path: root/lib/gitlab/markdown/label_reference_filter.rb
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-04-14 18:34:01 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-04-20 13:01:45 -0400
commitb3b8fc6c8a559b743d98577d07bc45a884e242a3 (patch)
tree72ffcac0405cbe78f90581f15010babc9e728f15 /lib/gitlab/markdown/label_reference_filter.rb
parent6189b24fddae66e1c2bb71c496301ff85701cb90 (diff)
downloadgitlab-ce-b3b8fc6c8a559b743d98577d07bc45a884e242a3.tar.gz
DRY up reference filters using ReferenceFilter base class
Diffstat (limited to 'lib/gitlab/markdown/label_reference_filter.rb')
-rw-r--r--lib/gitlab/markdown/label_reference_filter.rb43
1 files changed, 5 insertions, 38 deletions
diff --git a/lib/gitlab/markdown/label_reference_filter.rb b/lib/gitlab/markdown/label_reference_filter.rb
index 3bb84c50b93..f40b981ba60 100644
--- a/lib/gitlab/markdown/label_reference_filter.rb
+++ b/lib/gitlab/markdown/label_reference_filter.rb
@@ -1,16 +1,7 @@
-require 'html/pipeline'
-
module Gitlab
module Markdown
- # HTML filter that replaces label references with links. References within
- # <pre>, <code>, <a>, and <style> elements are ignored.
- #
- # Context options:
- # :project (required) - Current project.
- # :reference_class - Custom CSS class added to reference links.
- # :only_path - Generate path-only links.
- #
- class LabelReferenceFilter < HTML::Pipeline::Filter
+ # HTML filter that replaces label references with links.
+ class LabelReferenceFilter < ReferenceFilter
# Public: Find label references in text
#
# LabelReferenceFilter.references_in(text) do |match, id, name|
@@ -42,30 +33,10 @@ module Gitlab
)
}x
- # Don't look for references in text nodes that are children of these
- # elements.
- IGNORE_PARENTS = %w(pre code a style).to_set
-
def call
- doc.search('text()').each do |node|
- content = node.to_html
-
- next if project.nil?
- next unless content.match(LABEL_PATTERN)
- next if has_ancestor?(node, IGNORE_PARENTS)
-
- html = label_link_filter(content)
-
- next if html == content
-
- node.replace(html)
+ replace_text_nodes_matching(LABEL_PATTERN) do |content|
+ label_link_filter(content)
end
-
- doc
- end
-
- def validate
- needs :project
end
# Replace label references in text with links to the label specified.
@@ -83,7 +54,7 @@ module Gitlab
if label = project.labels.find_by(params)
url = url_for_label(project, label)
- klass = "gfm gfm-label #{context[:reference_class]}".strip
+ klass = reference_class(:label)
%(<a href="#{url}" class="#{klass}">#{render_colored_label(label)}</a>)
else
@@ -118,10 +89,6 @@ module Gitlab
{ name: name.tr('\'"', '') }
end
end
-
- def project
- context[:project]
- end
end
end
end