question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"paste-html" – error when pasting content in which A tag is wrapped in a text-formatting tag (i.e. STRONG)

See original GitHub issue

Do you want to request a feature or report a bug?

Bug

What’s the current behavior?

Go to https://hungerlyyak.htmlpasta.com/ and copy the content. The HTML is below:

<p>The most important thing is to copy this text <strong><a href="https://example.com/">and this A link</a></strong> that is wrapped in STRONG tags.</p>
<p>Open your console and see what it says when you paste.</p>

Then, go to the paste-html example. Open your developer console. Paste the content in the Slate Editor. It triggers an error:

Uncaught Error: The <text> hyperscript tag can only contain text content as children.

This is because the <strong> tag becomes a text tag (with bold: true) and then, there is an Element nested in it ({ type: "link", url:"https://example.com/", children: [{ text: "and this A link" }] } – which is a forbidden nesting as per Slate’s constraints.

Slate: 0.56.9 Browser: All OS: Mac

What’s the expected behavior?

I think the bolding should transfer and apply to the Text leaves nested within the Link Element.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:11

github_iconTop GitHub Comments

2reactions
davidgoldencommented, Jul 13, 2020

Maybe I’m misunderstanding your logic, but I’m thinking the goal is to return only valid children of the text node. Since find() returns ‘undefined’ if there aren’t any, but filter() will always return an array, it just seems cleaner to me.

1reaction
nikita-nikita-nikitacommented, Apr 16, 2021

in my case i just did this and it works but there was just a {type: "link"} maybe in some other cases that can doesn’t work fine

 if (TEXT_TAGS[nodeName]) {
    const attrs = TEXT_TAGS[nodeName](el);
    return children.map(child => {
      if(SlateElement.isElement(child)) {
        return jsx('element', child)
      }
      return jsx('text', attrs, child)
    })
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Outlook desktop email content pasted into web email gives error
It's the HTML formatting from Office. Outlook adds the P tag (for paragraphs) while gmail just uses DIV tags. I would not copy...
Read more >
Javascript trick for 'paste as plain text` in execCommand
Possible Solution: The way I can think of is to set listener for keyup events for ( Ctrl + V ) and strip...
Read more >
Basic Formatting | HTML text formatting, paragraphs and line ...
Note that when closing the original tag ( p ), all its attributes are taken with it, and all you need is the...
Read more >
dafont copy and paste
Many apps provide text formatting options to make the fonts look bold, for example ... content in invites or titles in labels and...
Read more >
Add text to frames in InDesign - Adobe Support
Add, paste, drag and drop, and place text in InDesign frames and ... The following options are available when you import a tagged-text...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found