Ionaru / Ionaru/easy-markdown-editor
afterImageUploaded should ignore query string distinguishing image files
- Dominant language
- JavaScript
- Stars
- 3.1k
- Forks
- 363
- PR merge metrics
- No merged PRs in 30d
Description
**Description**
I use Firebase Cloud Storage as image storage, which makes public image url be `https://...fileName.png?alt=media`.
When I call `onSuccess` handler after uploading and getting the public url, it inserts the content as normal link (`[title](url)`) while expected to insert as image (``).
This is because easymde calls `afterImageUploaded` function internally when `onSuccess` handler is called. It simply uses the last part of the image url (query string `?alt=media` included), which means any url which has query string will not be handled as image even if it really has the extension of image.
https://github.com/Ionaru/easy-markdown-editor/blob/072176a86ebbd17fabe47845866610e77e65f779/src/js/easymde.js#L810
```javascript
var imageName = url.substr(url.lastIndexOf('/') + 1);
var ext = imageName.substring(imageName.lastIndexOf('.') + 1);
// Check if media is an image
if (['png', 'jpg', 'jpeg', 'gif', 'svg'].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);
}
```
The part getting file extension from url should be like:
```javascript
var ext = url.split(/[#?]/)[0].split('.').pop().trim();
```
I took this example from: https://stackoverflow.com/a/47767860/5359376
**Expected behavior**
`afterImageUploaded` handler should ignore query string in the uploaded image url.
Also, it would be great if these extension or the tag choosing strategy be customizable.
Thank you.
Contributor guide
Research direction
Start in src/js/easymde.js around line 810, where afterImageUploaded derives the extension from the uploaded URL. Reproduce an upload URL containing a query string such as ?alt=media, then verify that the handler inserts image markdown rather than a normal link while preserving existing behavior for URLs without queries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100