[PF-498] Add normalization process for RichTextElement - #2965
Open
stevestreza-ksr wants to merge 1 commit into
Open
[PF-498] Add normalization process for RichTextElement#2965stevestreza-ksr wants to merge 1 commit into
stevestreza-ksr wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📲 What
This pull request does a normalization pass on RichTextElements converted from GraphQL so that nesting works properly with the elements we receive.
🤔 Why
The server has an internal HTML parser that converts an HTML element into a GraphQL type. These types can be nested. And due to the way the HTML parser works, that means elements like images can be added as children of a text node. But we need text and image nodes to be block-level nodes.
Example:
<div>Here's an image: <img ... /> Isn't it neat?</div>🛠 How
After converting the GraphQL elements to RichTextElements, we now have a function that scans all of the elements and replaces them with one or more "normalized" elements.
In the above example, the conversion turns that div into a Text block with three child elements [
Text,Photo,Text]. If this type of pattern is detected, the original element is removed and replaced with three standalone elements.The text nodes may also be empty (e.g. if the image is directly at the start or end of the block) so we filter out empty text blocks as well.