lexical icon indicating copy to clipboard operation
lexical copied to clipboard

LexicalBlockNormalizer

Open zurfyx opened this issue 2 months ago • 13 comments

LexicalBlockNormalizer (aka NestingEnforcementPlugin)

This was probably our first ever formal normalizer after some patches in the HTML importDOM functions (it has been internal only for a while). The idea behind this normalizer is to make sure that non-inline elements are always at the very top of the tree.

Invalid states can happen anytime and there is no mechanism to enforce them. The idea behind Schemas https://github.com/facebook/lexical/issues/3833 is still not very appealing for the fact that we trade-off state consistency for reliability which, from a user perspective, is still bad reliablity. The idea of normalization seems to have gotten more traction over the past years, when we opened an API to do static transforms and started standalone normalizers (i.e. table https://github.com/facebook/lexical/pull/5824). FWIW, I'm not a fan of static transforms but the point still stands.

While this plugin won't be the final shape of normalizers, this brings us a step closer to having a formal API to define plugins, which can standardize normalizers.

Credit for the implementation goes to @fantactuka, I just ported the code and adjusted the API.

Note for reviewers: the best test plan I can offer for this is the unit test itself. The 11 test cases will walk you through what this plugin can normalize.

zurfyx avatar May 04 '24 17:05 zurfyx