diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /lib/banzai/filter | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'lib/banzai/filter')
4 files changed, 22 insertions, 57 deletions
diff --git a/lib/banzai/filter/playable_link_filter.rb b/lib/banzai/filter/playable_link_filter.rb index 0a043aa809c..5b290ff08f6 100644 --- a/lib/banzai/filter/playable_link_filter.rb +++ b/lib/banzai/filter/playable_link_filter.rb @@ -52,7 +52,7 @@ module Banzai doc.document.create_element(media_type, media_element_attrs) end - def download_paragraph(doc, element) + def download_link(doc, element) link_content = element['title'] || element['alt'] link_element_attrs = { @@ -67,19 +67,15 @@ module Banzai link_element_attrs['data-canonical-src'] = element['data-canonical-src'] end - link = doc.document.create_element('a', link_content, link_element_attrs) - - doc.document.create_element('p').tap do |paragraph| - paragraph.children = link - end + doc.document.create_element('a', link_content, link_element_attrs) end def media_node(doc, element) - container_element_attrs = { class: "#{media_type}-container" } + container_element_attrs = { class: "media-container #{media_type}-container" } - doc.document.create_element( "div", container_element_attrs).tap do |container| + doc.document.create_element('span', container_element_attrs).tap do |container| container.add_child(media_element(doc, element)) - container.add_child(download_paragraph(doc, element)) + container.add_child(download_link(doc, element)) end end end diff --git a/lib/banzai/filter/references/label_reference_filter.rb b/lib/banzai/filter/references/label_reference_filter.rb index 3ae9c5f8d90..a019ae0108e 100644 --- a/lib/banzai/filter/references/label_reference_filter.rb +++ b/lib/banzai/filter/references/label_reference_filter.rb @@ -23,7 +23,8 @@ module Banzai label_relation = labels.where(title: label_names) end - return Label.none if (relation = [id_relation, label_relation].compact).empty? + relation = [id_relation, label_relation].compact + return Label.none if relation.all?(Label.none) Label.from_union(relation) end diff --git a/lib/banzai/filter/references/milestone_reference_filter.rb b/lib/banzai/filter/references/milestone_reference_filter.rb index d992e667056..94f7106d31e 100644 --- a/lib/banzai/filter/references/milestone_reference_filter.rb +++ b/lib/banzai/filter/references/milestone_reference_filter.rb @@ -23,7 +23,8 @@ module Banzai milestone_relation = find_milestones(parent, false).where(name: milestone_names) end - return Milestone.none if (relation = [iid_relation, milestone_relation].compact).empty? + relation = [iid_relation, milestone_relation].compact + return Milestone.none if relation.all?(Milestone.none) Milestone.from_union(relation).includes(:project, :group) end @@ -116,11 +117,11 @@ module Banzai # We don't support IID lookups because IIDs can clash between # group/project milestones and group/subgroup milestones. - params[:group_ids] = self_and_ancestors_ids(parent) unless find_by_iid + params[:group_ids] = group_and_ancestors_ids(parent) unless find_by_iid end end - def self_and_ancestors_ids(parent) + def group_and_ancestors_ids(parent) if group_context?(parent) parent.self_and_ancestors.select(:id) elsif project_context?(parent) diff --git a/lib/banzai/filter/references/reference_cache.rb b/lib/banzai/filter/references/reference_cache.rb index 816ce973cad..b2d47aba2d6 100644 --- a/lib/banzai/filter/references/reference_cache.rb +++ b/lib/banzai/filter/references/reference_cache.rb @@ -28,11 +28,18 @@ module Banzai @references_per_parent[parent_type] ||= begin refs = Hash.new { |hash, key| hash[key] = Set.new } - if Feature.enabled?(:milestone_reference_pattern, default_enabled: :yaml) - doc_search(refs) - else - node_search(nodes, 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 end @@ -163,39 +170,6 @@ 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 [ @@ -215,13 +189,6 @@ module Banzai 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 - - filter.requires_unescaping? ? unescape_html_entities(html) : html - end - def unescape_html_entities(text) CGI.unescapeHTML(text.to_s) end |