Skip to content

Editor: preserve markdown when copying and pasting - #3371

Open
AlexAndBear wants to merge 8 commits into
mainfrom
enhancement/markdown-clipboard-interoperability
Open

AlexAndBear wants to merge 8 commits into
mainfrom
enhancement/markdown-clipboard-interoperability

Conversation

@AlexAndBear

@AlexAndBear AlexAndBear commented Sep 14, 2026

Copy link
Copy Markdown
Member

Description

Improve Markdown clipboard handling in the rendered editor.

Copied selections from Markdown documents are serialized as Markdown text, so they can be pasted into Markdown-aware targets without switching to source mode. Pasted clipboard text is now inserted through the Markdown parser consistently, including when the clipboard also exposes an HTML payload.

Downside: rich formatting that only exists in the HTML clipboard payload, such as bold text copied from a web page, is not preserved in Markdown files. Rich note editing should use the .ocnote file extension for that use case.

Related Issue

How Has This Been Tested?

  • test environment: local macOS workspace, pnpm + Vitest
  • test case 1: pnpm test:unit --run packages/web-pkg/tests/unit/editor/extensions/markdownClipboard.spec.ts

Types of changes

  • Bugfix
  • Enhancement (a change that doesn't break existing code or deployments)
  • Breaking change (a modification that affects current functionality)
  • Technical debt (addressing code that needs refactoring or improvements)
  • Tests (adding or improving tests)
  • Documentation (updates or additions to documentation)
  • Maintenance (like dependency updates or tooling adjustments)

@AlexAndBear AlexAndBear self-assigned this Sep 14, 2026
@AlexAndBear
AlexAndBear force-pushed the enhancement/markdown-clipboard-interoperability branch 10 times, most recently from efbc6fb to 591dcff Compare September 14, 2026 23:24
@AlexAndBear
AlexAndBear force-pushed the enhancement/markdown-clipboard-interoperability branch from 591dcff to 8d24f77 Compare September 14, 2026 23:26

@JammingBen JammingBen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A paste of a single word or letter is always adding line breaks for some reason. E.g. have foobar in the editor, put the cursor after foo and paste a single letter. This results in 3 lines.

Comment on lines +26 to +28
// Let the original paste handler insert plain text inside code-like nodes.
// Parsing it as markdown would split pasted code into regular document blocks.
if (view.state.selection.$from.parent.type.spec.code) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably makes sense to guard inline code marks as well here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is an error in the native paste command, we already return false here, but the issue persists.
This is also the case on demo

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor: copying and pasting markdown

2 participants