Skip to content

Commit

Permalink
rich-text: Fix bug where bare tag name format types could not be regi…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
davilera and David Aguilera committed Dec 27, 2022
1 parent f2ff206 commit df84674
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/rich-text/src/register-format-type.js
Expand Up @@ -82,7 +82,10 @@ export function registerFormatType( name, settings ) {
richTextStore
).getFormatTypeForBareElement( settings.tagName );

if ( formatTypeForBareElement ) {
if (
formatTypeForBareElement &&
formatTypeForBareElement.name !== 'core/unknown'
) {
window.console.error(
`Format "${ formatTypeForBareElement.name }" is already registered to handle bare tag name "${ settings.tagName }".`
);
Expand Down
13 changes: 12 additions & 1 deletion packages/rich-text/src/test/register-format-type.js
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { select } from '@wordpress/data';
import { dispatch, select } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -11,10 +11,21 @@ import { unregisterFormatType } from '../unregister-format-type';
import { getFormatType } from '../get-format-type';
import { store as richTextStore } from '../store';

const UNKNOWN_FORMAT = {
name: 'core/unknown',
title: 'Clear Unknown Formatting',
tagName: '*',
className: null,
edit: () => null,
};

describe( 'registerFormatType', () => {
beforeAll( () => {
// Initialize the rich-text store.
require( '../store' );

// Register "core/unknown" format
dispatch( richTextStore ).addFormatTypes( UNKNOWN_FORMAT );
} );

afterEach( () => {
Expand Down

0 comments on commit df84674

Please sign in to comment.