[lexical] Feature: Support legacy 'align' attribute in ParagraphNode importDOM#8115
Merged
etrepum merged 2 commits intofacebook:mainfrom Feb 6, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
reviewed
Feb 5, 2026
Comment on lines
+178
to
+180
| if (align) { | ||
| node.setFormat(align as ElementFormatType); | ||
| } |
Collaborator
There was a problem hiding this comment.
Suggested change
| if (align) { | |
| node.setFormat(align as ElementFormatType); | |
| } | |
| if (align && align in ELEMENT_TYPE_TO_FORMAT) { | |
| node.setFormat(align); | |
| } |
setFormat doesn't handle unvalidated inputs correctly, will set __format to undefined instead of 0. This should either parse with align in ELEMENT_TYPE_TO_FORMAT and/or it should include an improvement to setFormat to handle invalid inputs more gracefully by using 0 in that situation.
setFormat(type: ElementFormatType): this {
const self = this.getWritable();
self.__format = type !== '' ? ELEMENT_TYPE_TO_FORMAT[type] : 0;
return this;
}9d3b753 to
fc57327
Compare
etrepum
approved these changes
Feb 6, 2026
rayterion
pushed a commit
to rayterion/lexical
that referenced
this pull request
Feb 8, 2026
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
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.
Summary
This PR fixes an issue where pasting legacy HTML content (e.g., from older editors or Word) containing the
alignattribute on<p>tags would lose its alignment information.Previously,
ParagraphNode.importDOMonly checkedelement.style.textAlign. It now falls back to thealignattribute if no CSS alignment is present.Details
$convertParagraphElementinLexicalParagraphNode.tsto checkelement.getAttribute('align')as a fallback.text-alignstill takes priority over the legacy attribute.<p align="right"><p style="text-align: center">Test Plan
LexicalParagraphNode.test.tspnpm run test-unit packages/lexical/src/nodes/__tests__/unit/LexicalParagraphNode.test.tspasses.