-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
fix: Markdown editor cannot bold with shortcut or add images from clipboard #24746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
@dagadevelop is attempting to deploy a commit to the Strapi Team on Vercel. A member of the Team first needs to authorize it. |
ecc3043 to
0af5f9e
Compare
…board
# Markdown Editor Improvements
## What does it do?
This PR fix two issues in the Markdown editor:
### 1. Keyboard Shortcuts for Text Formatting
- **Cmd+B / Ctrl+B**: Bold
- **Cmd+I / Ctrl+I**: Italic
- **Cmd+U / Ctrl+U**: Underline
- **Cmd+K / Ctrl+K**: Link
The shortcuts work just like the toolbar buttons - wrapping selected text or inserting
markdown with proper cursor positioning.
### 2. Automatic Upload of Pasted Images
- Detects when users paste images from clipboard (Cmd+V / Ctrl+V)
- Automatically uploads images to the server via `/upload` endpoint
- Inserts the uploaded images as markdown in the editor
- Supports single or multiple images at once
- Shows translated notifications with upload progress
## Why is it needed?
The Markdown editor previously lacked common keyboard shortcuts and required a manual
workflow for adding images, creating friction in the content editing experience.
## How to test it?
### Testing Keyboard Shortcuts
1. Open any content type with a Markdown field
2. Type some text or select existing text
3. Press the shortcuts:
- **Cmd+B** (Mac) or **Ctrl+B** (Windows/Linux) → Text should be wrapped with
`**bold**`
- **Cmd+I** or **Ctrl+I** → Text should be wrapped with `_italic_`
- **Cmd+U** or **Ctrl+U** → Text should be wrapped with `<u>underline</u>`
- **Cmd+K** or **Ctrl+K** → Text should be wrapped with `[text](link)`
### Testing Image Paste
1. Take a screenshot or copy an image from any source
2. Click inside the Markdown editor
3. Paste with **Cmd+V** or **Ctrl+V**
4. Verify:
- Notification appears: "Uploading image..."
- Image uploads to the server
- Success notification: "Image uploaded and inserted successfully"
- Image markdown is inserted in the editor: ``
5. Test multiple images:
- Copy multiple images (e.g., from Finder/Explorer)
- Paste in editor
- Verify notification: "Uploading X images..."
- All images should be uploaded and inserted
## Related issue(s)/PR(s)
Fix [strapi#24742](strapi#24742)
0af5f9e to
493d8f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your contribution! I have a couple of minor code style comments, and a bigger one about how to make the upload logic more maintainable in the future. Let me know if you're up for it, if not we could try to handle the images part internally and merge only the keyboard shortcuts part
| editorRef.current.on('change', changeHandler); | ||
|
|
||
| // Handle paste event to detect images | ||
| const handlePaste = (_cm: CodeMirror.Editor, event: ClipboardEvent) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you rename _cm to something like editor? we try to have explicit variable names, and CM in strapi generally refers to the content manager
| // Collect all image files | ||
| const imageFiles: File[] = []; | ||
| for (let i = 0; i < items.length; i++) { | ||
| const item = items[i]; | ||
| if (item.type.indexOf('image') !== -1) { | ||
| const file = item.getAsFile(); | ||
| if (file) { | ||
| imageFiles.push(file); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to match our code style better, could you use a combination of Array .filter and .map for this?
|
|
||
| try { | ||
| // Create FormData for the upload | ||
| const formData = new FormData(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this whole block of logic about uploading is too low level for this package. What would be a more viable solution would be to access the useUpload hook that the upload plugin uses internally. Unfortunately it's not currently exported, but you could set that up:
import { useUpload } from '@strapi/upload/strapi-admin'here- add an
exports.tsfile toupload/admin/srcthat re-exports useUpload, and would allow us to expose more in the future. Just like it's done in the content-manager export * from './exports'inupload/admin/src/index
Markdown Editor Improvements
What does it do?
This PR fix two issues in the Markdown editor:
1. Keyboard Shortcuts for Text Formatting
The shortcuts work just like the toolbar buttons - wrapping selected text or inserting
markdown with proper cursor positioning.
2. Automatic Upload of Pasted Images
/uploadendpointWhy is it needed?
The Markdown editor previously lacked common keyboard shortcuts and required a manual
workflow for adding images, creating friction in the content editing experience.
How to test it?
Testing Keyboard Shortcuts
**bold**_italic_<u>underline</u>[text](link)Testing Image Paste
Related issue(s)/PR(s)
Fix #24742