diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 2504f3be0a..ab45267b84 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -167,6 +167,21 @@ export function initGlobalDropzone() { file.uuid = data.uuid; const input = $(``).val(data.uuid); $dropzone.find('.files').append(input); + // Create a "Copy Link" element, to conveniently copy the image + // or file link as Markdown to the clipboard + const copyLinkElement = document.createElement('a'); + copyLinkElement.className = 'dz-remove'; + copyLinkElement.href = '#'; + copyLinkElement.innerHTML = ' Copy link'; + copyLinkElement.addEventListener('click', (e) => { + e.preventDefault(); + let fileMarkdown = `[${file.name}](/attachments/${file.uuid})`; + if (file.type.startsWith('image/')) { + fileMarkdown = `!${fileMarkdown}`; + } + navigator.clipboard.writeText(fileMarkdown); + }); + file.previewTemplate.appendChild(copyLinkElement); }); this.on('removedfile', (file) => { $(`#${file.uuid}`).remove();