Skip to content

Bug: Content copied from outside the editor sometimes isn't parsed correctly #69

Closed
@matthewlipski

Description

@matthewlipski

While copying & pasting in BlockNote works for the majority of content, there are 2 cases in which it breaks:

  1. When pasting two elements, e.g.:
<p>Foo</p>
<p>Bar<p>

Here, both elements are parsed as blockContent` and the editor doesn't know if they should be interpreted as two separate blocks or a single, nested, block. It always chooses the latter, meaning that the example is parsed as:

{
  block: {
    textContent: "Foo",
    blockGroup: {
      block: {
        textContent: "Bar"
      } 
    } 
  }
}

In this scenario, the type of the first element is also lost, so it's always interpreted as textContent.

  1. When pasting nested elements, e.g.:
<ul>
  <li>Foo
    <ul>
      <li>Bar</li>
    </ul>
  </li>
</ul>

Here, the nesting information is lost. This is mainly applicable to list items, since paragraph and heading elements can't be nested as per the HTML spec. When pasting list items into BlockNote, they too are parsed as blockContent, which can't have nested items. Therefore, the text of each nested item is concatenated to the end of the text of the parent item and the example gets parsed as:

{
  block: {
    listItemContent: "Foo Bar",
  }
}

I've already attempted to fix these issues on the copy-paste-new-architecture branch if it's of any help, though I haven't had much success.

Once this is working we'll also need additional tests for it.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingprio:midMedium priority

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions