aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-06-04 20:19:41 +0800
committerGitHub <noreply@github.com>2024-06-04 12:19:41 +0000
commit90008111181b874ac018455d8d7a2f8bfe6bc71e (patch)
tree717151249a67d79cbb3b19e3e53d5e587a829660 /web_src/js
parent4ca65fabdad75e39f9948b9a2a18e32edc98ec02 (diff)
downloadgitea-90008111181b874ac018455d8d7a2f8bfe6bc71e.tar.gz
gitea-90008111181b874ac018455d8d7a2f8bfe6bc71e.zip
Make pasted "img" tag has the same behavior as markdown image (#31235)
Fix #31230 --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'web_src/js')
-rw-r--r--web_src/js/features/comp/Paste.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/web_src/js/features/comp/Paste.js b/web_src/js/features/comp/Paste.js
index b26296d1fc..35a7ceaef8 100644
--- a/web_src/js/features/comp/Paste.js
+++ b/web_src/js/features/comp/Paste.js
@@ -100,13 +100,17 @@ async function handleClipboardImages(editor, dropzone, images, e) {
const {uuid} = await uploadFile(img, uploadUrl);
const {width, dppx} = await imageInfo(img);
- const url = `/attachments/${uuid}`;
let text;
if (width > 0 && dppx > 1) {
// Scale down images from HiDPI monitors. This uses the <img> tag because it's the only
// method to change image size in Markdown that is supported by all implementations.
+ // Make the image link relative to the repo path, then the final URL is "/sub-path/owner/repo/attachments/{uuid}"
+ const url = `attachments/${uuid}`;
text = `<img width="${Math.round(width / dppx)}" alt="${htmlEscape(name)}" src="${htmlEscape(url)}">`;
} else {
+ // Markdown always renders the image with a relative path, so the final URL is "/sub-path/owner/repo/attachments/{uuid}"
+ // TODO: it should also use relative path for consistency, because absolute is ambiguous for "/sub-path/attachments" or "/attachments"
+ const url = `/attachments/${uuid}`;
text = `![${name}](${url})`;
}
editor.replacePlaceholder(placeholder, text);