Skip to content

Conversation

@kimseongyu
Copy link
Contributor

@kimseongyu kimseongyu commented Jan 18, 2026

Description

Current Behavior:
There is an issue where markdown format tags (e.g. bold, italic) are incorrectly placed when a format starts or ends at a link boundary. This happens because the formatter attempts to minimize the number of tags by looking across inline element siblings, leading to the following bugs:

Format starting inside a link: When a format is applied to text within a link, the formatter fails to close the tag inside the link because it expects the format to continue into the parent's next sibling. This results in the tag opening inside the link but closing outside of it (Refer to #7817).

Format ending inside a link: Since formatting is applied only to the text node within the link and not the link element itself, the closing tag is often omitted or misplaced (Refer to #7503).

Changes in this PR:
I have simplified the getTextSibling() function to ensure correct tag placement.

Previously, the logic attempted to traverse siblings of inline elements (like links) to minimize the total number of markdown tags. While this aimed for "cleaner" markdown, it resulted in syntactically incorrect tag at boundaries.

This PR prioritizes structural correctness over tag minimization. By ensuring tags are closed and opened correctly relative to the link boundaries:

Markdown integrity is preserved even if it requires slightly more tags.

I have verified this fix against the reported issue and existing tests. All relevant tests, including those involving links, have passed.

PR Closes #7503, Closes #7811 , Closes #7817

Test plan

Before

before.mov

After

after.mov

…is at format boundary

The `getTextSibling()` function previously checked parent siblings for inline elements (like links) to determine format continuity. This caused incorrect markdown when:

- Links were at the start of formatted blocks (tags placed inside link) Refs facebook#7503
- Format continuity broke inside links but parent sibling had same. format

Simplified `getTextSibling()` to only check direct siblings, ensuring correct tag placement. Tests updated accordingly.
@vercel
Copy link

vercel bot commented Jan 18, 2026

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

Project Deployment Review Updated (UTC)
lexical Ready Ready Preview, Comment Jan 18, 2026 11:12am
lexical-playground Ready Ready Preview, Comment Jan 18, 2026 11:12am

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 Jan 18, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Jan 20, 2026
@etrepum etrepum added this pull request to the merge queue Jan 20, 2026
Merged via the queue into facebook:main with commit 51a83a7 Jan 20, 2026
40 checks passed
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

2 participants