fix(web-pkg): paste text/plain in plain text editor to keep markdown syntax - #3526
Open
AlexAndBear wants to merge 2 commits into
Open
AlexAndBear wants to merge 2 commits into
AlexAndBear wants to merge 2 commits into
Conversation
AlexAndBear
force-pushed
the
fix/plain-text-editor-paste
branch
from
October 1, 2026 19:30
3f40857 to
f98e701
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Copying content from the markdown editor and pasting it into a plain text file (e.g.
.txt) stripped the markdown syntax (#,**,-, code fences, …), even though the clipboard'stext/plainpayload contained proper markdown.ProseMirror prefers the
text/htmlclipboard payload overtext/plain. The plain text editor is a tiptap editor with a reduced schema (no headings, lists, marks, …), so the html got parsed into that schema and everything it couldn't represent was dropped. Nested list items even ended up at the end of the document.This adds a
plainTextClipboardextension to the plain text strategy:text/plain(falls back to the default handling if there is none)clipboardTextSerializeruses Tiptap'sgetTextBetween/getTextSerializersFromSchemahelpers withblockSeparator: '\n'(same as saving the file)clipboardTextParsermaps every line to a paragraph, keeping empty onesWhile testing, it turned out that both the new paste handler and the existing one in
markdownClipboard.tsalso pasted into read-only editors: ProseMirror runshandleDOMEventsbefore its own editable check. Both handlers now bail out when the editor isn't editable.Copy, paste, load and save now all follow the same "one paragraph per line" rule. Tiptap and ProseMirror don't offer an option to prefer
text/plainon paste or to keep empty lines, so those two parts stay custom.Related Issue
How Has This Been Tested?
pnpm vite+ docker backend), Chrome / Chromium via Playwright, unit tests via Vitest.mdfile with Cmd+A/Cmd+C, paste into a.txtfile with Cmd+V → markdown syntax is kept 1:1 (headings, marks, links, nested lists, ordered lists, quotes, code fences, tables).txtfile → empty lines are kept, no doubled line breaks\r\nand\rline endings are split correctly\n.txtinto.mdis unchanged (markdown gets parsed).txt/.mdeditor and press Cmd+V → content stays unchangedpnpm test:unit --run packages/web-pkg/tests/unit/editorTypes of changes