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

Keep id on paste if internal link points to it #31107

Merged
merged 3 commits into from
Sep 7, 2021

Conversation

juanruitina
Copy link
Contributor

@juanruitina juanruitina commented Apr 22, 2021

Description

With these changes, the block editor will keep the IDs in links when there's another link pointing to that ID. This is useful when pasting documents with internal links, e.g. when pasting text with footnotes from Microsoft Word, which used to work with the TinyMCE editor. Fixes #12784.

Sometimes internal links leverage the "name" attribute as the anchor instead of "id". However, the use of the name attribute for a elements is obsolete in HTML5; use of id is recommended instead; W3C Markup Validator also shows a warning. This code also saves the name attribute in links as the link's id (unless there's an id attribute already), and then removes it.

(Following @ellatrix feedback in #27677, these changes affect all links, not only footnotes and endnotes)

How has this been tested?

Tested locally with wp-env.

Types of changes

Bug fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR. (Doesn't apply)

@juanruitina juanruitina requested a review from ellatrix as a code owner April 22, 2021 17:40
@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Apr 22, 2021
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @juanruitina! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@juanruitina
Copy link
Contributor Author

@ellatrix, I accidentally removed the branch I used for #27677, so the PR closed. I took the chance to name the new branch following the developer guidelines. Apologies for the inconvenience.

Copy link
Member

@ellatrix ellatrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove name from the schema.

Otherwise this is great. Simple and generalised so that's really nice.

@ellatrix
Copy link
Member

Looks like there's something going wrong with the tests so you might have to rebase to re-run them again at a later time.

@juanruitina juanruitina force-pushed the fix/paste-links-with-id branch from b8eb52c to d77e7e8 Compare April 23, 2021 11:42
@juanruitina
Copy link
Contributor Author

juanruitina commented Apr 23, 2021

Thanks a lot @ellatrix for your indications and suggestions, I incorporated them and rebased as suggested. It seems I need approval for rerunning tests, can you do that?

@juanruitina juanruitina requested a review from ellatrix April 23, 2021 14:47
@ellatrix
Copy link
Member

@juanruitina You need to rebase to re-run them :)

@ellatrix
Copy link
Member

Oh, one last thing, could you add an paste integration test? I think they're in test/integration. You can put the MS Word data in an HTML file like the other tests.

@juanruitina juanruitina force-pushed the fix/paste-links-with-id branch 2 times, most recently from afa6c6f to 2b08c30 Compare May 24, 2021 16:38
@juanruitina juanruitina marked this pull request as draft May 24, 2021 16:39
@juanruitina juanruitina marked this pull request as ready for review May 24, 2021 16:42
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a>This is a paragraph with an anchor with no link pointing to it.</a></p>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellatrix Could you provide some more guidance on how could we unwrap text within links with no attributes (therefore with no use)? You mentioned removeInvalidHTML should handle it but I couldn't figure out how we could make sure it achieves that (it doesn't at the moment). It would be nice to clean it up a bit.

@juanruitina
Copy link
Contributor Author

I added a test in test/integration for the Word paste, seems to work.

(I did something wrong with the rebase and Github automatically asked for reviews from many code owners. I could undo the error, but not those review requests. Sorry for that!!! Geez, I need to get more familiar with git)

If link has obsolete name attribute, save as id and remove name
Remove links with no id nor href attributes (+ test)
Update raw handling readme: footnote support, LibreOffice
No need to remove name attribute, handled by removeInvalidHTML
@juanruitina juanruitina force-pushed the fix/paste-links-with-id branch from 2b08c30 to 8642ec3 Compare August 4, 2021 09:44
@Mamaduka Mamaduka added [Feature] Paste [Type] Bug An existing feature does not function as intended labels Sep 7, 2021
@Mamaduka Mamaduka merged commit eab8c63 into WordPress:trunk Sep 7, 2021
@github-actions
Copy link

github-actions bot commented Sep 7, 2021

Congratulations on your first merged pull request, @juanruitina! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts:

https://profiles.wordpress.org/me/profile/edit/

And if you don't have a WordPress.org account, you can create one on this page:

https://login.wordpress.org/register

Kudos!

@github-actions github-actions bot added this to the Gutenberg 11.5 milestone Sep 7, 2021
@Mamaduka
Copy link
Member

Mamaduka commented Sep 7, 2021

Thanks for working on this, @juanruitina, and congratulations on the first merged PR 🎉

@juanruitina juanruitina deleted the fix/paste-links-with-id branch January 26, 2022 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Paste First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Footnote Anchoring
3 participants