RichText: registerFormatType should allow identification by style rule
#15478 opened on May 7, 2019
Description
It seems only one
formatTypeat a time can register itself for controlling a barespanelement.It looks like something went wrong implementing this in Gutenberg. The format should have received a class (maybe
underline). Registeringbaretags is meant for semantic elements, notspanelements. Perhaps we need to allow identifying formats by style rules as well, when we want to avoid setting a class and detect existing formats in the content. Switching now would exclude previously applied formatting.https://github.com/Automattic/wp-calypso/pull/32808#issuecomment-489971816
Currently formatting in the content is identified either by "bare" element name (e.g. strong) or by class (e.g. span.my-custom-format). This can be limiting in cases where you can ID formatting by a style property, so you can also ID formatting that existed before Gutenberg, or wasn't applied by your format type. E.g.: underline and color.
Rules when matching:
- Should match the
tagNamefirst. - Should only have one CSS rule.
- Should match the rule's property, and store that with the value as a format attribute.
In case of underline, the rule is text-decoration. It's just an implementation detail that we're always going to set it to underline. Someone could decide to re-register underline with some style options.
For this reason, I'd also rename core/underline to core/text-decoration.
For color the above matching also makes sense.
Seems like a good first issue to me for anyone wanting to start with rich text. Happy to review it.