Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not convert a classic block with multiple links to blocks. Can't even paste multiple links #27551

Closed
wpgaurav opened this issue Dec 7, 2020 · 8 comments · Fixed by #27746
Labels
[Block] Embed Affects the Embed Block [Feature] Paste Good First Issue An issue that's suitable for someone looking to contribute for the first time [Type] Bug An existing feature does not function as intended

Comments

@wpgaurav
Copy link

wpgaurav commented Dec 7, 2020

Describe the bug
Whenever I try to:

  1. Paste multiple URLS (like a list of sites)
  2. Convert a classic editor block with multiple URLs.

It tries to embed those URLs as a single link.
Please see the screenshot:
https://gauravtiwari.org/wp-content/uploads/2020/12/screenshot-erro.gif
To reproduce
Steps to reproduce the behavior:

  • Paste multiple links at once, like these:
    The List of Sites: https://addthis.com https://elegantthemes.com https://generatepress.com https://woocommerce.com https://backlinko.com https://elementor.com https://elmastudio.de https://wptavern.com

  • OR if a Classic Block already has a list of links, Convert that to blocks.

Screenshots
https://gauravtiwari.org/wp-content/uploads/2020/12/screenshot-erro.gif

Editor version (please complete the following information):

  • WordPress version: [e.g: 5.5.3]
  • Does the website has Gutenberg plugin installed, or is it using the block editor that comes by default? [e.g: "gutenberg plugin", "default"] : Gutenberg is Installed.
  • If the Gutenberg plugin is installed, which version is it?: 9.4.1

Desktop (please complete the following information):

  • OS: MacOS
  • Browser Chrome
  • Version : 86
@talldan talldan added [Feature] Paste [Type] Bug An existing feature does not function as intended [Block] Embed Affects the Embed Block labels Dec 8, 2020
@talldan
Copy link
Contributor

talldan commented Dec 8, 2020

I can reproduce the issue when pasting into a paragraph block, it does indeed converted to an embed, and that embed then can't be transformed back into the original content using the 'Convert to Link' option as the spaces are removed.

I think this is the relevant code, it seems like isMatch should only return true if there's a single link in the textContent:

{
type: 'raw',
isMatch: ( node ) =>
node.nodeName === 'P' &&
/^\s*(https?:\/\/\S+)\s*$/i.test( node.textContent ),
transform: ( node ) => {
return createBlock( EMBED_BLOCK, {
url: node.textContent.trim(),
} );
},
},

This could be a fairly simple fix, so will label as Good First Issue.

Converting from a classic block worked ok for me. That might need further testing.

@talldan talldan added the Good First Issue An issue that's suitable for someone looking to contribute for the first time label Dec 8, 2020
@gaavar
Copy link
Contributor

gaavar commented Dec 8, 2020

  • Hi! I am a first-time contributor. Can I take up this issue?

@talldan
Copy link
Contributor

talldan commented Dec 9, 2020

That would be great @gaavar, let me know if you need any assistance!

@gaavar
Copy link
Contributor

gaavar commented Dec 9, 2020

@talldan thank you so much! I got stuck with some failures while setting up the dev environment on WSL2 Ubuntu. Is there a slack channel or similar for gutenberg where I can ask for assistance on this?

@talldan
Copy link
Contributor

talldan commented Dec 9, 2020

@gaavar What was the error?

There is a slack instance (https://wordpress.slack.com/signup#/), and it's the #core-editor channel for Gutenberg development.

Might also be worth searching the issues here to see if anyone else has had the same problem.

@gaavar
Copy link
Contributor

gaavar commented Dec 12, 2020

My dev environment is all set up! Here's what I noticed: when I use a classic block and copy-paste a list of links (each on a new line),
the classic block doesn't carry over the new line and hence every link from the list appears to be concatenated together and when trying to use Convert to blocks, the embed feature gets triggered but treats everything as a single link. I am guessing the embed feature is supposed to be triggered for each link separately. Is that the correct expected behavior? @talldan @wpgaurav

@gaavar
Copy link
Contributor

gaavar commented Dec 13, 2020

As a follow-up, examining the code portion I think the regex can be modified a bit to return True only if there's one URL in the node.textContent. @talldan Is this a good idea or is there a better solution?

@talldan
Copy link
Contributor

talldan commented Dec 14, 2020

@gaavar Glad you got it all set up 🎉

Yep, I think modifying the regex as you describe looks would be a good thing to try first. 👍

gaavar added a commit to gaavar/gutenberg that referenced this issue Dec 16, 2020
gaavar added a commit to gaavar/gutenberg that referenced this issue Dec 16, 2020
gaavar added a commit to gaavar/gutenberg that referenced this issue Jan 3, 2021
gaavar added a commit to gaavar/gutenberg that referenced this issue Jan 4, 2021
gaavar added a commit to gaavar/gutenberg that referenced this issue Jan 4, 2021
gaavar added a commit to gaavar/gutenberg that referenced this issue Jan 4, 2021
talldan pushed a commit that referenced this issue Jan 13, 2021
…iggering embed block (#27746)

* modified isMatch to permit multiple links to be pasted without triggering embed block(#27551)

* modified isMatch to permit multiple links to be pasted without triggering embed block(#27551)

* modified isMatch to permit multiple links to be pasted without triggering embed block(#27551)

* modified isMatch to permit multiple links to be pasted without triggering embed block(#27551)

* modified isMatch to permit multiple links to be pasted without triggering embed block(#27551)

* modified isMatch to permit multiple links to be pasted without triggering embed block(#27551)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Embed Affects the Embed Block [Feature] Paste Good First Issue An issue that's suitable for someone looking to contribute for the first time [Type] Bug An existing feature does not function as intended
Projects
None yet
3 participants