Tiptap: Paste from notepad

Created on 27 Jul 2020  路  3Comments  路  Source: ueberdosis/tiptap

When I copy and paste blank text from notepad, divided into paragraphs, blank lines are lost.

Example. The text I'm copying:
111111
222222

333333

Text after pasting:
111111
222222
333333

Perhaps there is an extension that can solve this problem?

bug help wanted should have a test in v2

Most helpful comment

Here's a bad solution, but it worked:

import {Slice, Fragment, Node} from 'prosemirror-model'

function clipboardTextParser(text, context, plain)
{
    const blocks = text.replace().split(/(?:\r\n?|\n)/);
    const nodes = [];

    blocks.forEach(line => {
        let nodeJson = {type: "paragraph"};
        if (line.length > 0) {
            nodeJson.content = [{type: "text", text: line}]
        }
        let node = Node.fromJSON(context.doc.type.schema, nodeJson);
        nodes.push(node);
    });

    const fragment = Fragment.fromArray(nodes);
    return Slice.maxOpen(fragment);
}
....
      tipTapEditor: new Editor({
          editorProps: {
              clipboardTextParser: clipboardTextParser,
          },
      })
....

All 3 comments

This is a big issue for us as well, any tips on how to patch in the current version?

Currently, I don鈥檛 have an idea, not even for the new version. 馃槙

Open for suggestions!

Here's a bad solution, but it worked:

import {Slice, Fragment, Node} from 'prosemirror-model'

function clipboardTextParser(text, context, plain)
{
    const blocks = text.replace().split(/(?:\r\n?|\n)/);
    const nodes = [];

    blocks.forEach(line => {
        let nodeJson = {type: "paragraph"};
        if (line.length > 0) {
            nodeJson.content = [{type: "text", text: line}]
        }
        let node = Node.fromJSON(context.doc.type.schema, nodeJson);
        nodes.push(node);
    });

    const fragment = Fragment.fromArray(nodes);
    return Slice.maxOpen(fragment);
}
....
      tipTapEditor: new Editor({
          editorProps: {
              clipboardTextParser: clipboardTextParser,
          },
      })
....
Was this page helpful?
0 / 5 - 0 ratings

Related issues

agentq15 picture agentq15  路  3Comments

chrisjbrown picture chrisjbrown  路  3Comments

afwn90cj93201nixr2e1re picture afwn90cj93201nixr2e1re  路  3Comments

santicros picture santicros  路  3Comments

pk-pressf1 picture pk-pressf1  路  3Comments