[lexical-markdown] Bug Fix: text left outside a markdown link keeps its format - #9131
Merged
potatowagon merged 1 commit intoSep 8, 2026
Conversation
…ts format When the LINK transformer sees more opening than closing brackets it splits the match, keeps part of the text inside the link and puts the rest back as a sibling TextNode before it. The link's own text node gets the replaced node's format, but the sibling was a bare $createTextNode, so any bold, italic or strikethrough on that leftover text was dropped. Importing "*[h[ello](https://lexical.dev)*" produced a plain "[h" next to an italic "ello". Both nodes stand in for the same TextNode, so both now carry its format.
Om-singhaI
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
September 8, 2026 00:45
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
potatowagon
approved these changes
Sep 8, 2026
Merged
This branch was successfully deployed
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
Importing
*[h[ello](https://lexical.dev)*loses the italic on[h.importRegExpmatches here with alinkTextofh[ello, which has more opening than closing brackets, so the LINK transformer splits it:ellogoes inside the link and[hgoes back as a sibling TextNode ahead of it. The link's own text node is given the format of the TextNode being replaced, but the sibling is a bare$createTextNode, so the format on that half is dropped. One italic run comes back as a plain[hnext to an italicello.Both new nodes stand in for the same TextNode, so it's inconsistent for only one of them to keep its format. The rest of the import path already preserves it:
importTextMatchTransformerhandsreplacea node that came out ofsplitText, andsplitTextcopies format, style and detail onto every piece it makes.$createAutoLinkNode_in@lexical/linkgets it right for the same reason. The markdown LINK transformer is the one place that builds its leftover node by hand.The fix reads the format once before the replace detaches the node, then applies it to both nodes.
I kept this to the format alone. The link's text node doesn't copy style or detail today either, so putting those on just the sibling would swap one mismatch for another.
Test plan
Added the italic case to the
IMPORT_AND_EXPORTtable right beside the existing[h[ello](...)split case, so it runs through import, export and the selection check. It needs anmdAfterExportbecause the exporter writes the italic as two runs,*[h*[*ello*](https://lexical.dev).Before
New test in place,
MarkdownTransformers.tsstill atmain:After
packages/lexical-linkstays green too, 10 files and 187 tests.