ProseMirror / prosemirror

The ProseMirror WYSIWYM editor
http://prosemirror.net/
MIT License
7.59k stars 335 forks source link

Copy-pasted text wraps into "<meta charset='utf-8'><p data-pm-slice="1 1 []">" #1425

Closed andrey-skl closed 9 months ago

andrey-skl commented 9 months ago

Note: maybe happened after this fix https://discuss.prosemirror.net/t/pasting-url-copied-from-ios-device-issues/5944/6

  1. Use following versions ("prosemirror-view": "1.31.8" works just fine):
    "prosemirror-model": "1.18.3",
    "prosemirror-state": "1.4.2",
    "prosemirror-view": "1.32.2",
  2. use this schema:
    const mySchema = new Schema({
    nodes: {
    doc: {
      code: true,
      content: "paragraph"
    },
    paragraph: {
      code: true,
      content: "inline*",
      toDOM: () => ["p", 0]
    },
    text: { group: "inline" }
    }
    });
  3. Open example https://codesandbox.io/s/stoic-noyce-dtxypm?file=/src/editor/index.jsx
  4. Copy text in editor
  5. Paste text in editor

Expected: text is pasted as it was copied Actual: text is wrapped into meta-tags <meta charset='utf-8'><p data-pm-slice="1 1 []">world</p> 2023-10-31 12 20 31

marijnh commented 9 months ago

Don't use code: true on node types thar aren't code blocks. That should fix this.

andrey-skl commented 9 months ago

@marijnh Thank you for your response!

As I see in our codebase, it was done intentionally to workaround some issues:

    doc: {
      code: true, // hack for https://github.com/ProseMirror/prosemirror-view/blob/5339e196f374a9ed2a6f1de85e3472b66fb8d844/src/clipboard.js#L44
      content: 'paragraph',
    },
    paragraph: {
      code: true, //hack for https://github.com/ProseMirror/prosemirror-view/blob/91af53423b55a725ecaf42d34329c7642d88285a/src/domchange.js#L42
      content: 'inline*',
      toDOM: () => ['p', 0],
    },

I will check if the issues we tried to work around are still actual, thank you

marijnh commented 9 months ago

Though I really do recommend not having code: true where it doesn't make sense, there was a recent regression that was causing the HTML markup to be pasted like this. Attached patch should resolve that.