From 189c5347bef6c182ed00e2b845cdce5678abbbce Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 10 Apr 2015 16:38:34 -0400 Subject: [PATCH] Add name-based referencing to LabelReferenceFilter --- lib/gitlab/markdown/label_reference_filter.rb | 43 +++++-- .../markdown/label_reference_filter_spec.rb | 113 +++++++++++++++--- 2 files changed, 130 insertions(+), 26 deletions(-) diff --git a/lib/gitlab/markdown/label_reference_filter.rb b/lib/gitlab/markdown/label_reference_filter.rb index 9753d0ac0f9..3bb84c50b93 100644 --- a/lib/gitlab/markdown/label_reference_filter.rb +++ b/lib/gitlab/markdown/label_reference_filter.rb @@ -13,25 +13,34 @@ module Gitlab class LabelReferenceFilter < HTML::Pipeline::Filter # Public: Find label references in text # - # LabelReferenceFilter.references_in(text) do |match, label| - # "#{label}" + # LabelReferenceFilter.references_in(text) do |match, id, name| + # "#{Label.find(id)}" # end # # text - String text to search. # - # Yields the String match and the Integer label ID. + # Yields the String match, an optional Integer label ID, and an optional + # String label name. # # Returns a String replaced with the return of the block. def self.references_in(text) text.gsub(LABEL_PATTERN) do |match| - yield match, $~[:label].to_i + yield match, $~[:label_id].to_i, $~[:label_name] end end # Pattern used to extract label references from text # - # This pattern supports cross-project references. - LABEL_PATTERN = /~(?