[lexical-markdown] Bug Fix: Fix incorrect format tag placement at link boundaries#8085
Merged
etrepum merged 1 commit intofacebook:mainfrom Jan 20, 2026
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
approved these changes
Jan 20, 2026
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.
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