core icon indicating copy to clipboard operation
core copied to clipboard

[Block Editor]: Add Markdown Copy & Paste to the Editor

Open MariaFernandez778 opened this issue 1 year ago • 5 comments

Idea

Our users need a better way to move formatted content between our editor and other apps that use Markdown. Right now, it's a manual, frustrating process.

User Story

As a content creator, I want to copy and paste content as Markdown so I can move my work around without losing all my formatting.

The Goal

Make content creation faster and less annoying. Success looks like:

  • Users can successfully copy/paste Markdown without needing a workaround.
  • The feature works seamlessly with content from our AI tool.
  • We see fewer complaints about transferring content.
Image

Acceptance Criteria

This all centers around a new right-click menu in the editor.

1. The New Right-Click Menu

  • Right-clicking in the editor opens a custom menu.
  • This menu MUST include the standard options: Cut, Copy, Paste.
  • It MUST also have our two new options: Copy as Markdown and Paste from Markdown.
  • Standard keyboard shortcuts (Ctrl+X, Ctrl+C, Ctrl+V) should continue to work as they always have (for regular text, not Markdown).

2. Copying as Markdown

  • When a user selects text and chooses "Copy as Markdown" from the right-click menu...
  • Then the text should be copied to their clipboard in Markdown format (e.g., bold text becomes **bold text**).

3. Pasting from Markdown

  • When a user has Markdown text in their clipboard and chooses "Paste from Markdown"...
  • Then the text should appear in our editor with the correct formatting (e.g., # My Title becomes a proper H1 heading).

[!IMPORTANT] Standard Paste is Sacred: To be super clear, Ctrl+V should NOT try to parse Markdown. It should paste plain text as it does today. The user must explicitly choose "Paste from Markdown" from the menu to get the special formatting.

Documentation

  • We need to decide exactly which Markdown elements we'll support for day one (e.g., headings, bold, lists, links). Let's start with the most common ones.
  • We need to document that some custom blocks (e.g., contentlets) may not be successfully converted to markdown.

NPM Packages

For Markdown → HTML Conversion

For converting Markdown into HTML (for your "Paste from Markdown" feature), the best choice for most projects is marked

For HTML → Markdown Conversion

For converting HTML from your editor into Markdown text (for your "Copy as Markdown" feature), the clear winner and industry standard is turndown

How to Test It

  • ✅ Does the new right-click menu show up correctly on Chrome, Firefox, and Safari?
  • ✅ Do Cut, Copy, and Paste still work normally on Mac and Windows?
  • ✅ Test copying text -> "Copy as Markdown" -> pasting into a plain text app. Does it look like Markdown?
  • ✅ Test copying Markdown from another app -> "Paste from Markdown." Does it format correctly in our editor?
  • ✅ Try it with AI-generated content. Does it work?
  • ✅ What happens if you "Paste from Markdown" with text that isn't Markdown? (It should probably just paste it as plain text).

MariaFernandez778 avatar Apr 29 '25 01:04 MariaFernandez778

QA Failed

When clicking on any button on the new Context Menu inside the Block Editor, shows a second Context Menu.

This only happens on Firefox and Firefox-based browsers.

On Chrome and Chromium-based browsers, text gets pasted right away without a second Context Menu.

Screenshots

https://github.com/user-attachments/assets/5ce7ffa2-bd4c-45f5-bc6e-544d3f5917ab

zJaaal avatar Aug 08 '25 17:08 zJaaal

This is a security restriction in Firefox. We can’t bypass or customize the paste confirmation prompt at this time. As a UX follow-up, I’ll improve the UI so the context menu stays open until the user accepts the Firefox confirmation.

References

  • MDN - Clipboard API: Security considerations: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API#security_considerations
  • MDN - Clipboard.readText(): https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/readText
  • Bugzilla - Firefox clipboard read prompt: https://bugzilla.mozilla.org/show_bug.cgi?id=1744524

rjvelazco avatar Aug 08 '25 17:08 rjvelazco

QA Passed

Since the research result was an expected behavior due to security reasons and the Markdown parsing is working as expected.

We can set this ticket as done.

PS: This feature is awesome.

zJaaal avatar Aug 08 '25 21:08 zJaaal

Edge Cases that Need Docs

Case 1: Markdown Copy/Paste Limitation

We currently have a limitation with the Copy as Markdown feature in the Block Editor. If the user attempts to copy Block Editor content as markdown, any contentlets will appear as empty lines in the output. This happens because there is no existing translation/mapping from a contentlet to markdown format.

https://github.com/user-attachments/assets/84178edb-7470-4513-8971-7d7cb7e03c2a

Case 2: Firefox Paste Restriction When using the Paste as Markdown option from the context menu in Firefox, the browser will display a confirmation modal before proceeding with the paste action. This is due to a security restriction specific to Firefox, and it is expected behavior.

https://github.com/user-attachments/assets/92184c02-fc26-4c4a-a4c7-0ed58cc97090

References

cc: @jdcmsd @fmontes

rjvelazco avatar Aug 11 '25 17:08 rjvelazco