diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /lib/banzai/filter/kroki_filter.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'lib/banzai/filter/kroki_filter.rb')
-rw-r--r-- | lib/banzai/filter/kroki_filter.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/banzai/filter/kroki_filter.rb b/lib/banzai/filter/kroki_filter.rb index 845c7f2bc0a..713ff2439fc 100644 --- a/lib/banzai/filter/kroki_filter.rb +++ b/lib/banzai/filter/kroki_filter.rb @@ -14,7 +14,10 @@ module Banzai return doc unless settings.kroki_enabled diagram_selectors = ::Gitlab::Kroki.formats(settings) - .map { |diagram_type| %(pre[lang="#{diagram_type}"] > code) } + .map do |diagram_type| + %(pre[lang="#{diagram_type}"] > code, + pre > code[lang="#{diagram_type}"]) + end .join(', ') xpath = Gitlab::Utils::Nokogiri.css_to_xpath(diagram_selectors) @@ -22,7 +25,7 @@ module Banzai diagram_format = "svg" doc.xpath(xpath).each do |node| - diagram_type = node.parent['lang'] + diagram_type = node.parent['lang'] || node['lang'] 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}" />)) @@ -33,8 +36,8 @@ module Banzai img_tag.set_attribute('hidden', '') if lazy_load img_tag.set_attribute('class', 'js-render-kroki') - img_tag.set_attribute('data-diagram', node.parent['lang']) - img_tag.set_attribute('data-diagram-src', "data:text/plain;base64,#{Base64.strict_encode64(node.content)}") + img_tag.set_attribute('data-diagram', diagram_type) + img_tag.set_attribute('data-diagram-src', "data:text/plain;base64,#{Base64.strict_encode64(diagram_src)}") node.parent.replace(img_tag) end |