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

rich-text: Fix bug where bare tag name format types could not be registered #46798

Merged
merged 2 commits into from Dec 27, 2022

Conversation

davilera
Copy link
Contributor

What?

This PR fixes #46795. It also tweaks the test suite to account for the reported bug.

Why?

Users should be able to register format types to handle bare tag names. Unfortunately, this is currently not possible as described in #46795.

How?

When registering a new format type name/format, the code now checks if the existing format type that handles a bare tag name xxx is core/unknown. If it is, it means nobody registered a specific format type for tag name xxx and, therefore, name/format should be allowed.

Testing Instructions

  1. Go to the post editor
  2. Open your browser's developer tools
  3. In the JavaScript console, type the following:
wp.richText.registerFormatType( 'name/format', {
  title: 'Test bare tag format',
  tagName: 'xxx',
  className: null,
  edit: () => null,
} );

It should work.

  1. Then type the following:
wp.richText.registerFormatType( 'name/another-format', {
  title: 'Test bare tag format',
  tagName: 'xxx',
  className: null,
  edit: () => null,
} );

It should fail because tag name xxx is already handled by name/format (registered in step 3).

Copy link
Member

@noahtallen noahtallen left a comment

Choose a reason for hiding this comment

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

This change makes a lot of sense, and works great testing locally.

I tried the following code in the browser console:

wp.richText.unregisterFormatType( 'core/link' )

wp.richText.registerFormatType( 'my/link', {
  title: 'Test link format',
  tagName: 'a',
  className: null,
  edit: () => null,
} );

this fails on trunk, but works in this branch. Let's ship so that we can create a patch release! (I can handle that 👍 )

I think it makes sense to move forward on this quickly. If further changes are needed, I think those could be addressed in a follow-up, given that this is an important bug fix for plugin compatibility.

@noahtallen noahtallen added [Type] Bug An existing feature does not function as intended [Package] Rich text /packages/rich-text labels Dec 27, 2022
@noahtallen noahtallen added this to the Gutenberg 14.8 milestone Dec 27, 2022
@noahtallen noahtallen changed the title Fix/46795 rich-text: Fix bug where bare tag name formatters could not be registered Dec 27, 2022
@noahtallen noahtallen changed the title rich-text: Fix bug where bare tag name formatters could not be registered rich-text: Fix bug where bare tag name format types could not be registered Dec 27, 2022
@noahtallen noahtallen merged commit df84674 into WordPress:trunk Dec 27, 2022
noahtallen pushed a commit that referenced this pull request Dec 27, 2022
…stered (#46798)

* Add “core/unknown” format in test to properly flag bug.

* Allow registration of a bare tag name format when said tag is handled by “core/unknown”.

Co-authored-by: David Aguilera <david.aguilera@neliosoftware.com>
@noahtallen noahtallen linked an issue Dec 27, 2022 that may be closed by this pull request
spacedmonkey pushed a commit that referenced this pull request Jan 17, 2023
…stered (#46798)

* Add “core/unknown” format in test to properly flag bug.

* Allow registration of a bare tag name format when said tag is handled by “core/unknown”.

Co-authored-by: David Aguilera <david.aguilera@neliosoftware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Rich text /packages/rich-text [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to register format type to handle bare tag name link icon missing in block editor
2 participants