Skip to content

[lexical] Feature: Support legacy 'align' attribute in ParagraphNode importDOM#8115

Merged
etrepum merged 2 commits intofacebook:mainfrom
Sa-Te:fix/paragraph-alignment-paste
Feb 6, 2026
Merged

[lexical] Feature: Support legacy 'align' attribute in ParagraphNode importDOM#8115
etrepum merged 2 commits intofacebook:mainfrom
Sa-Te:fix/paragraph-alignment-paste

Conversation

@Sa-Te
Copy link
Copy Markdown
Contributor

@Sa-Te Sa-Te commented Feb 5, 2026

Summary

This PR fixes an issue where pasting legacy HTML content (e.g., from older editors or Word) containing the align attribute on <p> tags would lose its alignment information.

Previously, ParagraphNode.importDOM only checked element.style.textAlign. It now falls back to the align attribute if no CSS alignment is present.

Details

  • Modified $convertParagraphElement in LexicalParagraphNode.ts to check element.getAttribute('align') as a fallback.
  • Ensures modern CSS text-align still takes priority over the legacy attribute.
  • Added comprehensive unit tests covering:
  • Legacy <p align="right">
  • Modern <p style="text-align: center">
  • Conflict resolution (CSS priority)

Test Plan

  • Added new unit tests in LexicalParagraphNode.test.ts
  • Verified pnpm run test-unit packages/lexical/src/nodes/__tests__/unit/LexicalParagraphNode.test.ts passes.

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Feb 5, 2026 11:56am
lexical-playground Ready Ready Preview, Comment Feb 5, 2026 11:56am

Request Review

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 5, 2026
@etrepum etrepum changed the title fix(lexical): Support legacy 'align' attribute in ParagraphNode importDOM [lexical] Feature: Support legacy 'align' attribute in ParagraphNode importDOM Feb 5, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Feb 5, 2026
Comment on lines +178 to +180
if (align) {
node.setFormat(align as ElementFormatType);
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
  }

@etrepum etrepum added this pull request to the merge queue Feb 6, 2026
Merged via the queue into facebook:main with commit 3d1f4e5 Feb 6, 2026
39 checks passed
rayterion pushed a commit to rayterion/lexical that referenced this pull request Feb 8, 2026
@etrepum etrepum mentioned this pull request Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants