summaryrefslogtreecommitdiff
path: root/lib/banzai/filter/kroki_filter.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-03-01 18:28:24 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-03-01 18:28:24 +0000
commit47414496d427785d86832bcaca617233f904a2e0 (patch)
tree55c0e9671c5f513654fabdfc6dea1982528a5f9e /lib/banzai/filter/kroki_filter.rb
parent6b75388b67c35271bc18f2dbd41a72accd927808 (diff)
downloadgitlab-ce-47414496d427785d86832bcaca617233f904a2e0.tar.gz
Add latest changes from gitlab-org/security/gitlab@15-9-stable-ee
Diffstat (limited to 'lib/banzai/filter/kroki_filter.rb')
-rw-r--r--lib/banzai/filter/kroki_filter.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/banzai/filter/kroki_filter.rb b/lib/banzai/filter/kroki_filter.rb
index 26f42c6b194..2b9e2a22c11 100644
--- a/lib/banzai/filter/kroki_filter.rb
+++ b/lib/banzai/filter/kroki_filter.rb
@@ -9,6 +9,8 @@ module Banzai
# HTML that replaces all diagrams supported by Kroki with the corresponding img tags.
# If the source content is large then the hidden attribute is added to the img tag.
class KrokiFilter < HTML::Pipeline::Filter
+ include ActionView::Helpers::TagHelper
+
MAX_CHARACTER_LIMIT = 2000
def call
@@ -27,9 +29,11 @@ module Banzai
diagram_format = "svg"
doc.xpath(xpath).each do |node|
diagram_type = node.parent['lang'] || node['lang']
+ next unless diagram_selectors.include?(diagram_type)
+
diagram_src = node.content
image_src = create_image_src(diagram_type, diagram_format, diagram_src)
- img_tag = Nokogiri::HTML::DocumentFragment.parse(%(<img src="#{image_src}" />))
+ img_tag = Nokogiri::HTML::DocumentFragment.parse(content_tag(:img, nil, src: image_src))
img_tag = img_tag.children.first
next if img_tag.nil?