gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Rich Text: allow underscores in Format Type class name format

Open alexandrebuffet opened this issue 3 years ago • 0 comments

When we want to register a format type with a class that contains one or more underscore characters "_", we get the error message A class name must begin with a letter, followed by any number of hyphens, letters, or numbers. in the editor and the format is not registered.

For example, the error is triggered if I declare a "Counter Number" format type only available in a "Counter" block and want this format to apply a with the counter__number class name (I want to respect BEM naming convention inside the block) on the selection.

I've noticed that the corresponding regex in registerFormatType which checks the classname format, introduced in #10209 by @ellatrix, doesn't include the character.

This character is allowed in CSS selectors and is present in the regex of the sanitize_html_class formatting function if I'm not mistaken.

Could we concider adding the character in the regular expression to authorize this character in Format Type class names?

alexandrebuffet avatar Nov 27 '23 19:11 alexandrebuffet