diff options
Diffstat (limited to 'lib/banzai/filter/references/reference_cache.rb')
-rw-r--r-- | lib/banzai/filter/references/reference_cache.rb | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/lib/banzai/filter/references/reference_cache.rb b/lib/banzai/filter/references/reference_cache.rb index 24b8b4984cd..816ce973cad 100644 --- a/lib/banzai/filter/references/reference_cache.rb +++ b/lib/banzai/filter/references/reference_cache.rb @@ -28,20 +28,11 @@ module Banzai @references_per_parent[parent_type] ||= begin refs = Hash.new { |hash, key| hash[key] = Set.new } - nodes.each do |node| - prepare_node_for_scan(node).scan(regex) do - parent_path = if parent_type == :project - full_project_path($~[:namespace], $~[:project]) - else - full_group_path($~[:group]) - end - - ident = filter.identifier($~) - refs[parent_path] << ident if ident - end + if Feature.enabled?(:milestone_reference_pattern, default_enabled: :yaml) + doc_search(refs) + else + node_search(nodes, refs) end - - refs end end @@ -172,6 +163,39 @@ module Banzai delegate :project, :group, :parent, :parent_type, to: :filter + # Deprecated: https://gitlab.com/gitlab-org/gitlab/-/issues/336268 + def node_search(nodes, refs) + nodes.each do |node| + prepare_node_for_scan(node).scan(regex) do + parent_path = if parent_type == :project + full_project_path($~[:namespace], $~[:project]) + else + full_group_path($~[:group]) + end + + ident = filter.identifier($~) + refs[parent_path] << ident if ident + end + end + + refs + end + + def doc_search(refs) + prepare_doc_for_scan(filter.doc).to_enum(:scan, regex).each do + parent_path = if parent_type == :project + full_project_path($~[:namespace], $~[:project]) + else + full_group_path($~[:group]) + end + + ident = filter.identifier($~) + refs[parent_path] << ident if ident + end + + refs + end + def regex strong_memoize(:regex) do [ @@ -185,6 +209,13 @@ module Banzai Gitlab::SafeRequestStore["banzai_#{parent_type}_refs".to_sym] ||= {} end + def prepare_doc_for_scan(doc) + html = doc.to_html + + filter.requires_unescaping? ? unescape_html_entities(html) : html + end + + # Deprecated: https://gitlab.com/gitlab-org/gitlab/-/issues/336268 def prepare_node_for_scan(node) html = node.to_html |