diff --git a/cypress/e2e/4-image-upload/index.html b/cypress/e2e/4-image-upload/index.html new file mode 100644 index 0000000..7ab798a --- /dev/null +++ b/cypress/e2e/4-image-upload/index.html @@ -0,0 +1,24 @@ + + + + + + Default + + + + + + + + + + diff --git a/cypress/e2e/4-image-upload/upload.cy.js b/cypress/e2e/4-image-upload/upload.cy.js new file mode 100644 index 0000000..0e4fd2a --- /dev/null +++ b/cypress/e2e/4-image-upload/upload.cy.js @@ -0,0 +1,20 @@ +/// + +describe('Upload', () => { + beforeEach(() => { + cy.visit(__dirname + '/index.html'); + }); + + it('upload an image should insert a mock image url', () => { + cy.get('.EasyMDEContainer button.upload-image').click(); + cy.get('.EasyMDEContainer input[type=file]').selectFile({ + contents: Cypress.Buffer.from('', 'utf-8'), + fileName: 'test.jpg', + mimeType: 'image/jpeg' + }, { + action: 'drag-drop', + force: true + }); + cy.get('.EasyMDEContainer .CodeMirror').contains('![test.jpg](https://test.com/test.jpg)'); + }); +}); diff --git a/src/js/easymde.js b/src/js/easymde.js index de0d975..fa88137 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -878,18 +878,10 @@ function afterImageUploaded(editor, url) { var cm = editor.codemirror; var stat = getState(cm); var options = editor.options; + // TODO: Get the image name from the original file name var imageName = url.substr(url.lastIndexOf('/') + 1); - var ext = imageName.substring(imageName.lastIndexOf('.') + 1).replace(/\?.*$/, '').toLowerCase(); - - // Check if media is an image - if (['png', 'jpg', 'jpeg', 'gif', 'svg', 'apng', 'avif', 'webp'].includes(ext)) { - _replaceSelection(cm, stat.image, options.insertTexts.uploadedImage, url); - } else { - var text_link = options.insertTexts.link; - text_link[0] = '[' + imageName; - _replaceSelection(cm, stat.link, text_link, url); - } - + var text_link = [`${options.insertTexts.image[0]}${imageName}`, options.insertTexts.image[1]]; + _replaceSelection(cm, stat.image, text_link, url); // show uploaded image filename for 1000ms editor.updateStatusBar('upload-image', editor.options.imageTexts.sbOnUploaded.replace('#image_name#', imageName)); setTimeout(function () {