Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-03-31 03:00:32 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-03-31 03:00:32 +0300
commit1153e17b2d34c50834251038269ac11f18219bdf (patch)
tree20b80086422da0d03cb3a1af0300858570c35e7e /lib/banzai/filter
parentd111c2d301f43d0b6de98f47da39d2b107ce17a1 (diff)
Add latest changes from gitlab-org/security/gitlab@14-9-stable-ee
Diffstat (limited to 'lib/banzai/filter')
-rw-r--r--lib/banzai/filter/kroki_filter.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/banzai/filter/kroki_filter.rb b/lib/banzai/filter/kroki_filter.rb
index 3803302c324..9aa2afce5a8 100644
--- a/lib/banzai/filter/kroki_filter.rb
+++ b/lib/banzai/filter/kroki_filter.rb
@@ -6,8 +6,10 @@ require "asciidoctor/extensions/asciidoctor_kroki/extension"
module Banzai
module Filter
# 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
+ MAX_CHARACTER_LIMIT = 2000
+
def call
return doc unless settings.kroki_enabled
@@ -21,7 +23,12 @@ module Banzai
diagram_format = "svg"
doc.xpath(xpath).each do |node|
diagram_type = node.parent['lang']
- img_tag = Nokogiri::HTML::DocumentFragment.parse(%(<img src="#{create_image_src(diagram_type, diagram_format, node.content)}"/>))
+ diagram_src = node.content
+ image_src = create_image_src(diagram_type, diagram_format, diagram_src)
+ lazy_load = diagram_src.length > MAX_CHARACTER_LIMIT
+ other_attrs = lazy_load ? "hidden" : ""
+
+ img_tag = Nokogiri::HTML::DocumentFragment.parse(%(<img class="js-render-kroki" src="#{image_src}" #{other_attrs} />))
node.parent.replace(img_tag)
end