mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-07-04 00:24:29 -06:00
Merge d8e8fdbb7362d2fcea1ccd43671bab52459598ed into 2996b67ec95ec69000ee03ccaee4fcca26cfc701
This commit is contained in:
commit
2df79e4bd8
24
cypress/e2e/4-image-upload/index.html
Normal file
24
cypress/e2e/4-image-upload/index.html
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Default</title>
|
||||||
|
<link rel="stylesheet" href="../../../dist/easymde.min.css">
|
||||||
|
<script src="../../../dist/easymde.min.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<textarea id="textarea"></textarea>
|
||||||
|
<script>
|
||||||
|
const easyMDE = new EasyMDE({
|
||||||
|
uploadImage: true,
|
||||||
|
showIcons: ["upload-image"],
|
||||||
|
imageUploadFunction: (file, onSuccess) => {
|
||||||
|
onSuccess('https://test.com/test.jpg')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
20
cypress/e2e/4-image-upload/upload.cy.js
Normal file
20
cypress/e2e/4-image-upload/upload.cy.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/// <reference types="cypress" />
|
||||||
|
|
||||||
|
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('');
|
||||||
|
});
|
||||||
|
});
|
@ -878,18 +878,10 @@ function afterImageUploaded(editor, url) {
|
|||||||
var cm = editor.codemirror;
|
var cm = editor.codemirror;
|
||||||
var stat = getState(cm);
|
var stat = getState(cm);
|
||||||
var options = editor.options;
|
var options = editor.options;
|
||||||
|
// TODO: Get the image name from the original file name
|
||||||
var imageName = url.substr(url.lastIndexOf('/') + 1);
|
var imageName = url.substr(url.lastIndexOf('/') + 1);
|
||||||
var ext = imageName.substring(imageName.lastIndexOf('.') + 1).replace(/\?.*$/, '').toLowerCase();
|
var text_link = [`${options.insertTexts.image[0]}${imageName}`, options.insertTexts.image[1]];
|
||||||
|
_replaceSelection(cm, stat.image, text_link, url);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// show uploaded image filename for 1000ms
|
// show uploaded image filename for 1000ms
|
||||||
editor.updateStatusBar('upload-image', editor.options.imageTexts.sbOnUploaded.replace('#image_name#', imageName));
|
editor.updateStatusBar('upload-image', editor.options.imageTexts.sbOnUploaded.replace('#image_name#', imageName));
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user