diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-12-15 17:51:16 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-12-15 17:51:16 +0300 |
commit | 7781bda9bd82997f4a03de4cf911b1156ceb2cde (patch) | |
tree | a632a12b295694232205e2190f784f9bb79235ee /lib/gitlab/reference_extractor.rb | |
parent | 9451db3819ae45734c4343e55a74d347cdacf70d (diff) |
Move Markdown/reference logic from Gitlab::Markdown to Banzai
Diffstat (limited to 'lib/gitlab/reference_extractor.rb')
-rw-r--r-- | lib/gitlab/reference_extractor.rb | 53 |
1 files changed, 9 insertions, 44 deletions
diff --git a/lib/gitlab/reference_extractor.rb b/lib/gitlab/reference_extractor.rb index e83167fa7d7..42f7c26f3c4 100644 --- a/lib/gitlab/reference_extractor.rb +++ b/lib/gitlab/reference_extractor.rb @@ -1,62 +1,27 @@ -require 'gitlab/markdown' +require 'banzai' module Gitlab # Extract possible GFM references from an arbitrary String for further processing. - class ReferenceExtractor - attr_accessor :project, :current_user, :load_lazy_references + class ReferenceExtractor < Banzai::ReferenceExtractor + attr_accessor :project, :current_user - def initialize(project, current_user = nil, load_lazy_references: true) + def initialize(project, current_user = nil) @project = project @current_user = current_user - @load_lazy_references = load_lazy_references - @texts = [] @references = {} + + super() end - def analyze(text, options = {}) - @texts << Gitlab::Markdown.render(text, options.merge(project: project)) + def analyze(text, context = {}) + super(text, context.merge(project: project)) end %i(user label issue merge_request snippet commit commit_range).each do |type| define_method("#{type}s") do - @references[type] ||= pipeline_result(type) + @references[type] ||= references(type, project: project, current_user: current_user) end end - - private - - # Instantiate and call HTML::Pipeline with a single reference filter type, - # returning the result - # - # filter_type - Symbol reference type (e.g., :commit, :issue, etc.) - # - # Returns the results Array for the requested filter type - def pipeline_result(filter_type) - filter = Gitlab::Markdown::ReferenceFilter[filter_type] - - context = { - pipeline: :reference_extraction, - - project: project, - current_user: current_user, - - # ReferenceGathererFilter - load_lazy_references: false, - reference_filter: filter - } - - values = @texts.flat_map do |html| - text_context = context.dup - result = Gitlab::Markdown.render_result(html, text_context) - result[:references][filter_type] - end.uniq - - if @load_lazy_references - values = Gitlab::Markdown::ReferenceFilter::LazyReference.load(values).uniq - end - - values - end end end |