diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 23:02:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 23:02:30 +0300 |
commit | 41fe97390ceddf945f3d967b8fdb3de4c66b7dea (patch) | |
tree | 9c8d89a8624828992f06d892cd2f43818ff5dcc8 /lib/banzai | |
parent | 0804d2dc31052fb45a1efecedc8e06ce9bc32862 (diff) |
Add latest changes from gitlab-org/gitlab@14-9-stable-eev14.9.0-rc42
Diffstat (limited to 'lib/banzai')
-rw-r--r-- | lib/banzai/filter/front_matter_filter.rb | 5 | ||||
-rw-r--r-- | lib/banzai/filter/image_link_filter.rb | 14 | ||||
-rw-r--r-- | lib/banzai/filter/task_list_filter.rb | 3 |
3 files changed, 19 insertions, 3 deletions
diff --git a/lib/banzai/filter/front_matter_filter.rb b/lib/banzai/filter/front_matter_filter.rb index 705400a5497..c788137e122 100644 --- a/lib/banzai/filter/front_matter_filter.rb +++ b/lib/banzai/filter/front_matter_filter.rb @@ -9,7 +9,10 @@ module Banzai html.sub(Gitlab::FrontMatter::PATTERN) do |_match| lang = $~[:lang].presence || lang_mapping[$~[:delim]] - ["```#{lang}:frontmatter", $~[:front_matter].strip!, "```", "\n"].join("\n") + before = $~[:before] + before = "\n#{before}" if $~[:encoding].presence + + "#{before}```#{lang}:frontmatter\n#{$~[:front_matter]}```\n" end end end diff --git a/lib/banzai/filter/image_link_filter.rb b/lib/banzai/filter/image_link_filter.rb index ed0a01e6277..44acc7805b4 100644 --- a/lib/banzai/filter/image_link_filter.rb +++ b/lib/banzai/filter/image_link_filter.rb @@ -8,11 +8,17 @@ module Banzai # Find every image that isn't already wrapped in an `a` tag, create # a new node (a link to the image source), copy the image as a child # of the anchor, and then replace the img with the link-wrapped version. + # + # If `link_replaces_image` context parameter is provided, the image is going + # to be replaced with a link to an image. def call doc.xpath('descendant-or-self::img[not(ancestor::a)]').each do |img| + link_replaces_image = !!context[:link_replaces_image] + html_class = link_replaces_image ? 'with-attachment-icon' : 'no-attachment-icon' + link = doc.document.create_element( 'a', - class: 'no-attachment-icon', + class: html_class, href: img['data-src'] || img['src'], target: '_blank', rel: 'noopener noreferrer' @@ -21,7 +27,11 @@ module Banzai # make sure the original non-proxied src carries over to the link link['data-canonical-src'] = img['data-canonical-src'] if img['data-canonical-src'] - link.children = img.clone + link.children = if link_replaces_image + img['alt'] || img['data-src'] || img['src'] + else + img.clone + end img.replace(link) end diff --git a/lib/banzai/filter/task_list_filter.rb b/lib/banzai/filter/task_list_filter.rb index c6b402575cb..896f67cb875 100644 --- a/lib/banzai/filter/task_list_filter.rb +++ b/lib/banzai/filter/task_list_filter.rb @@ -9,6 +9,9 @@ require 'task_list/filter' module Banzai module Filter class TaskListFilter < TaskList::Filter + def render_item_checkbox(item) + "<task-button></task-button>#{super}" + end end end end |