Skip to content

[lexical-markdown] Bug Fix: Prevent Markdown links with empty string link text from being automatically removed - #7919

Closed
adambolcsfoldi wants to merge 1 commit into
meta:mainfrom
adambolcsfoldi:main
Closed

adambolcsfoldi wants to merge 1 commit into
meta:mainfrom
adambolcsfoldi:main

Conversation

@adambolcsfoldi

Copy link
Copy Markdown
Contributor

Description

Currently any markdown link where the link text is an empty string, e.g. [](https://lexical.dev), will be automatically removed on transformation. According to the CommonMark Spec, it's a valid link.
With this pull request the removal of the link's text node is prevented by using the Unmergeable flag.

Not sure what the desired behaviour is here. Admittedly, a link without a corresponding text isn't terribly useful unless handled by the UI layer in some way.
An option would be to not parse it as a valid link as is currently done when the link destination is empty string ([some link title]()), even despite being compliant with the CommonMark Spec.

Test plan

Before

Before.Link.disappears.mov

After

After.-.Link.persists.mov

@meta-cla

meta-cla Bot commented Oct 13, 2025

Copy link
Copy Markdown

Hi @adambolcsfoldi!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@vercel

vercel Bot commented Oct 13, 2025 •

Copy link
Copy Markdown

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

Project Deployment Preview Comments Updated (UTC)
lexical Ready Ready Preview Comment Oct 13, 2025 2:26pm
lexical-playground Ready Ready Preview Comment Oct 13, 2025 2:26pm

@etrepum

etrepum commented Oct 13, 2025

Copy link
Copy Markdown
Collaborator

I don't think that strict compliance is useful here, an empty unmergeable TextNode is going to cause other problems (you can't really interact with it). A zwsp might be better if you really wanted to parse such a construct. There are plenty of other instances where better conformance to the commonmark spec would be useful but I don't think this is one of them.

@adambolcsfoldi

Copy link
Copy Markdown
Contributor Author

I don't think that strict compliance is useful here, an empty unmergeable TextNode is going to cause other problems (you can't really interact with it). A zwsp might be better if you really wanted to parse such a construct. There are plenty of other instances where better conformance to the commonmark spec would be useful but I don't think this is one of them.

I can definitely get behind that.
However, I do think the current behaviour where the user input just vanishes feels quite broken. Should it then instead not be parsed as a markdown link at all, unless the length of the link text > 0?
So, [](https://lexical.dev) will not be parsed as a link, the same way [some text]() isn't now, but [a](https://lexical.dev) would be and result in a.

@etrepum

etrepum commented Oct 13, 2025

Copy link
Copy Markdown
Collaborator

That's probably slightly better than dropping it altogether, but I don't have a strong preference about that. lexical isn't specifically a markdown editor so lossless transformation isn't really the expectation. It's certainly something that could be built but not very easily with the architecture of the current @lexical/markdown package (but there's nothing special about that package, someone could publish or contribute a better one).

@adambolcsfoldi

Copy link
Copy Markdown
Contributor Author

Closed in favour of a more useful solution here: #7923

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — 7ddb4abb Deployed Oct 13, 2025 by vercel[bot]
Preview – lexical — 7ddb4abb Deployed Oct 13, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants