summaryrefslogtreecommitdiff
path: root/lib/gitlab/diff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-06-03 15:09:26 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-06-03 15:09:26 +0000
commitf5f6cb45c73c8aa059c3006a3696014522a41a4b (patch)
treebde1e1c22c83276f49858e827909a1e13ef0f0c2 /lib/gitlab/diff
parentc74f702c747d1b14c3ddea951ceb7970941dc8f5 (diff)
downloadgitlab-ce-f5f6cb45c73c8aa059c3006a3696014522a41a4b.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/diff')
-rw-r--r--lib/gitlab/diff/line.rb2
-rw-r--r--lib/gitlab/diff/rendered/notebook/diff_file.rb17
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/gitlab/diff/line.rb b/lib/gitlab/diff/line.rb
index 316a0d2815a..75127098600 100644
--- a/lib/gitlab/diff/line.rb
+++ b/lib/gitlab/diff/line.rb
@@ -10,7 +10,7 @@ module Gitlab
attr_reader :marker_ranges
attr_writer :text, :rich_text
- attr_accessor :index, :old_pos, :new_pos, :line_code, :type
+ attr_accessor :index, :old_pos, :new_pos, :line_code, :type, :embedded_image
def initialize(text, type, index, old_pos, new_pos, parent_file: nil, line_code: nil, rich_text: nil)
@text = text
diff --git a/lib/gitlab/diff/rendered/notebook/diff_file.rb b/lib/gitlab/diff/rendered/notebook/diff_file.rb
index 1f064d8af50..68011555c3c 100644
--- a/lib/gitlab/diff/rendered/notebook/diff_file.rb
+++ b/lib/gitlab/diff/rendered/notebook/diff_file.rb
@@ -14,6 +14,7 @@ module Gitlab
LOG_IPYNBDIFF_TIMEOUT = 'IPYNB_DIFF_TIMEOUT'
LOG_IPYNBDIFF_INVALID = 'IPYNB_DIFF_INVALID'
LOG_IPYNBDIFF_TRUNCATED = 'IPYNB_DIFF_TRUNCATED'
+ EMBEDDED_IMAGE_PATTERN = ' ![](data:image'
attr_reader :source_diff
@@ -69,7 +70,6 @@ module Gitlab
Timeout.timeout(timeout_time) do
IpynbDiff.diff(source_diff.old_blob&.data, source_diff.new_blob&.data,
raise_if_invalid_nb: true,
- hide_images: true,
diffy_opts: { include_diff_info: true })&.tap do
log_event(LOG_IPYNBDIFF_GENERATED)
end
@@ -109,6 +109,9 @@ module Gitlab
line.type = "#{line.type || 'unchanged'}-nomappinginraw" unless addition_line_maps[line.new_pos] || removal_line_maps[line.old_pos]
line.line_code = line_code(line)
+
+ line.rich_text = image_as_rich_text(line)
+
line
end
@@ -152,6 +155,18 @@ module Gitlab
Gitlab::ErrorTracking.log_exception(error) if error
nil
end
+
+ def image_as_rich_text(line)
+ # Strip the initial +, -, or space for the diff context
+ line_text = line.text[1..]
+
+ if line_text.starts_with?(EMBEDDED_IMAGE_PATTERN)
+ image_body = line_text.delete_prefix(EMBEDDED_IMAGE_PATTERN).delete_suffix(')')
+ "<img src=\"data:image#{CGI.escapeHTML(image_body)}\">".html_safe
+ else
+ line.rich_text
+ end
+ end
end
end
end