diff --git a/frontend/src/markdown-editor.js b/frontend/src/markdown-editor.js index 98efee2e73..21cce8af61 100644 --- a/frontend/src/markdown-editor.js +++ b/frontend/src/markdown-editor.js @@ -26,6 +26,7 @@ const { siteRoot, serviceUrl, seafileCollabServer } = window.app.config; const userInfo = window.app.userInfo; const userName = userInfo.username; let dirPath = Utils.getDirName(filePath); +const IMAGE_SUFFIXES = ['png', 'PNG', 'jpg', 'JPG', 'gif', 'GIF']; function getImageFileNameWithTimestamp() { var d = Date.now(); @@ -730,8 +731,15 @@ class MarkdownEditor extends React.Component { } getInsertLink = (repoID, filePath) => { - const innerURL = serviceUrl + '/lib/' + repoID + '/file' + Utils.encodePath(filePath); const fileName = Utils.getFileName(filePath); + const suffix = fileName.slice(fileName.indexOf('.') + 1); + if (IMAGE_SUFFIXES.includes(suffix)) { + seafileAPI.getFileDownloadLink(repoID, filePath).then((res) => { + window.richMarkdownEditor.addLink(fileName, res.data, true); + }); + return; + } + let innerURL = serviceUrl + '/lib/' + repoID + '/file' + Utils.encodePath(filePath); window.richMarkdownEditor.addLink(fileName, innerURL); }