summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKerri Miller <kerrizor@kerrizor.com>2019-06-03 14:52:58 -0700
committerKerri Miller <kerrizor@kerrizor.com>2019-06-05 16:19:45 -0700
commitfb3d40cb61eaff46bc10d3d49d499bd5d34a6be1 (patch)
treee809169c40e27143b19897ead3cdb3f1466b4009
parentf44eba8c0e537362ccf362480517f12ee7c73130 (diff)
downloadgitlab-ce-fb3d40cb61eaff46bc10d3d49d499bd5d34a6be1.tar.gz
Extend #parse to accept a suggestions_filter_enabled param
This will allow the front end to specify the behavior as needed.
-rw-r--r--app/services/preview_markdown_service.rb4
-rw-r--r--lib/gitlab/diff/suggestions_parser.rb6
2 files changed, 7 insertions, 3 deletions
diff --git a/app/services/preview_markdown_service.rb b/app/services/preview_markdown_service.rb
index 7386530f45f..2b4c4ae68e2 100644
--- a/app/services/preview_markdown_service.rb
+++ b/app/services/preview_markdown_service.rb
@@ -38,7 +38,9 @@ class PreviewMarkdownService < BaseService
head_sha: params[:head_sha],
start_sha: params[:start_sha])
- Gitlab::Diff::SuggestionsParser.parse(text, position: position, project: project)
+ Gitlab::Diff::SuggestionsParser.parse(text, position: position,
+ project: project,
+ supports_suggestion: params[:preview_suggestions])
end
def preview_sugestions?
diff --git a/lib/gitlab/diff/suggestions_parser.rb b/lib/gitlab/diff/suggestions_parser.rb
index c8c03d5d001..6e17ffaf6ff 100644
--- a/lib/gitlab/diff/suggestions_parser.rb
+++ b/lib/gitlab/diff/suggestions_parser.rb
@@ -10,10 +10,12 @@ module Gitlab
# Returns an array of Gitlab::Diff::Suggestion which represents each
# suggestion in the given text.
#
- def parse(text, position:, project:)
+ def parse(text, position:, project:, supports_suggestion: true)
return [] unless position.complete?
- html = Banzai.render(text, project: nil, no_original_data: true)
+ html = Banzai.render(text, project: nil,
+ no_original_data: true,
+ suggestions_filter_enabled: supports_suggestion)
doc = Nokogiri::HTML(html)
suggestion_nodes = doc.search('pre.suggestion')