2018-12-13 19:17:19 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-01-21 17:26:11 +00:00
|
|
|
# Generated HTML is transformed back to GFM by app/assets/javascripts/behaviors/markdown/nodes/code_block.js
|
2018-12-13 19:17:19 +00:00
|
|
|
module Banzai
|
|
|
|
module Filter
|
|
|
|
class SuggestionFilter < HTML::Pipeline::Filter
|
|
|
|
# Class used for tagging elements that should be rendered
|
2019-09-10 08:11:43 +00:00
|
|
|
TAG_CLASS = 'js-render-suggestion'
|
2018-12-13 19:17:19 +00:00
|
|
|
|
2021-06-01 21:10:06 +00:00
|
|
|
CSS = 'pre.language-suggestion > code'
|
|
|
|
XPATH = Gitlab::Utils::Nokogiri.css_to_xpath(CSS).freeze
|
|
|
|
|
2018-12-13 19:17:19 +00:00
|
|
|
def call
|
|
|
|
return doc unless suggestions_filter_enabled?
|
|
|
|
|
2021-06-01 21:10:06 +00:00
|
|
|
doc.xpath(XPATH).each do |node|
|
2018-12-13 19:17:19 +00:00
|
|
|
node.add_class(TAG_CLASS)
|
|
|
|
end
|
|
|
|
|
|
|
|
doc
|
|
|
|
end
|
|
|
|
|
|
|
|
def suggestions_filter_enabled?
|
|
|
|
context[:suggestions_filter_enabled]
|
|
|
|
end
|
2019-03-13 13:57:05 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def project
|
|
|
|
context[:project]
|
|
|
|
end
|
2018-12-13 19:17:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|