Skip to content

Conversation

@dagadevelop
Copy link
Contributor

@dagadevelop dagadevelop commented Oct 30, 2025

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: ![alt](url)
  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 #24742

@vercel
Copy link

vercel bot commented Oct 30, 2025

@dagadevelop is attempting to deploy a commit to the Strapi Team on Vercel.

A member of the Team first needs to authorize it.

@oiorain oiorain added source: core:content-manager Source is core/content-manager package pr: fix This PR is fixing a bug community Changes and fixes created by community members labels Oct 30, 2025
@dagadevelop dagadevelop force-pushed the fix-for-#24742 branch 2 times, most recently from ecc3043 to 0af5f9e Compare October 31, 2025 15:14
…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: `![alt](url)`
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)
@dagadevelop dagadevelop reopened this Oct 31, 2025
@remidej remidej self-assigned this Nov 5, 2025
@remidej remidej self-requested a review November 5, 2025 11:10
Copy link
Contributor

@remidej remidej left a 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) => {
Copy link
Contributor

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

Comment on lines +99 to +109
// 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);
}
}
}
Copy link
Contributor

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();
Copy link
Contributor

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.ts file to upload/admin/src that 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' in upload/admin/src/index

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Changes and fixes created by community members pr: fix This PR is fixing a bug source: core:content-manager Source is core/content-manager package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown editor cannot bold or add images

3 participants