You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge Request: Fix Font-Size Loss for Text Nodes from Google Docs/Microsoft Word (#7718)
Description
This change addresses issue #7718, where font-size styles are lost when importing content from Google Docs or Microsoft Word into the Lexical editor. Specifically, text nodes (#text) were not inheriting styles from their parent elements, resulting in missing formatting such as font-size.
Changes
Added a new condition in the createNodesFromDOM function to handle text nodes (node.nodeName === '#text').
Checks if the text node has a non-empty/non-null value (node.nodeValue) and if its parent node has a style attribute.
If conditions are met, applies the parent's style attribute value (e.g., font-size:11pt;) to the first TextNode in transformOutput.node, ensuring styles like font-size are preserved.
Uses getAttribute('style') to safely retrieve the parent's inline styles, defaulting to an empty string if no styles exist.
Impact
Fixes font-size loss for text nodes when importing content from Google Docs or Microsoft Word.
Preserves inline styles (e.g., font-size, color) applied to parent elements, ensuring accurate rendering in the Lexical editor.
Maintains existing behavior for non-text nodes and nodes without parent styles.
No breaking changes; the change is isolated to text nodes with styled parents.
Testing
Verified that text nodes from Google Docs/Microsoft Word imports now retain parent styles (e.g., font-size:11pt;).
Confirmed no regressions for non-text nodes or nodes without parent styles.
Tested with sample documents containing styled text to ensure styles are correctly applied to TextNode.__style.
There is already an in-progress PR #7719 that solves this in a more appropriate way, with tests. It's not desired behavior for the default TextNode implementation to copy all styles. The expected behavior is to only handle specific styles that are part of the TextNode model.
There is already an in-progress PR #7719 that solves this in a more appropriate way, with tests. It's not desired behavior for the default TextNode implementation to copy all styles. The expected behavior is to only handle specific styles that are part of the TextNode model.
Can i just take the font size attribute from the complete style of the Parent Node and apply it ?
Using a regular expression i can pick the font-size attribute.
No, there's also the matter of keeping the toolbar in sync and writing tests. The approach in PR #7719 is preferable and almost done. I wouldn't invest any more time in this PR since it will just get closed once that PR is merged.
No, there's also the matter of keeping the toolbar in sync and writing tests. The approach in PR #7719 is preferable and almost done. I wouldn't invest any more time in this PR since it will just get closed once that PR is merged.
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
CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
3 participants
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.
Merge Request: Fix Font-Size Loss for Text Nodes from Google Docs/Microsoft Word (#7718)
Description
This change addresses issue #7718, where font-size styles are lost when importing content from Google Docs or Microsoft Word into the Lexical editor. Specifically, text nodes (#text) were not inheriting styles from their parent elements, resulting in missing formatting such as font-size.
Changes
Added a new condition in the createNodesFromDOM function to handle text nodes (node.nodeName === '#text').
Checks if the text node has a non-empty/non-null value (node.nodeValue) and if its parent node has a style attribute.
If conditions are met, applies the parent's style attribute value (e.g., font-size:11pt;) to the first TextNode in transformOutput.node, ensuring styles like font-size are preserved.
Uses getAttribute('style') to safely retrieve the parent's inline styles, defaulting to an empty string if no styles exist.
Impact
Fixes font-size loss for text nodes when importing content from Google Docs or Microsoft Word.
Preserves inline styles (e.g., font-size, color) applied to parent elements, ensuring accurate rendering in the Lexical editor.
Maintains existing behavior for non-text nodes and nodes without parent styles.
No breaking changes; the change is isolated to text nodes with styled parents.
Testing
Verified that text nodes from Google Docs/Microsoft Word imports now retain parent styles (e.g., font-size:11pt;).
Confirmed no regressions for non-text nodes or nodes without parent styles.
Tested with sample documents containing styled text to ensure styles are correctly applied to TextNode.__style.
Closes #7718