payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
24.93k stars 1.59k forks source link

richtext-lexical: markdown transformer for links separated by newline not working as expected #8049

Closed AlessioGr closed 1 month ago

AlessioGr commented 2 months ago

https://github.com/user-attachments/assets/9662c1ad-cd67-4d0b-bd65-85a5ea160a6e

If a link spans 2 paragraphs, this works as expected. However, if a link spans 2 newlines, when converting back from link markdown => lexical, the link is not preserved.

Solution 1: use new multiline markdown transformers (in feat/lexical-mdx branch) for links, and match multiple lines. This will be hard, especially making sure newlines and new paragraphs are transformers correctly. However, this is more expected behavior - GitHub markdown works the same way (though GitHub does not differentiate between newlines and paragraphs)

Solution 2: Split up link into 2 links for newlines. This is how it currently works for links spanning multiple paragraphs. Not an amazing solution in my opinion, but will probably be easier to implement

GermanJablo commented 1 month ago

I spent a good amount of time trying to modify the transformers for CodeBlocks and Links, using the ElementTransformer, as well as your new MultilineElementTransformer.

However, I later realized that the solution was not there. The problem is not in converting a code block or a link from or to markdown, but in importing an arbitrary markdown string, which may contain code blocks or links inside, into a Lexical editor.

This requires a sanitization of the markdown string that must follow certain rules to comply with the CommonMark spec. I have opened a PR in the Lexical repository explaining all this.

EDIT: PR has been merged. I think I'll leave this issue open to make sure it works as expected in the next upgrade.

GermanJablo commented 1 month ago

ok, a second attempt was necessary, but now it is merged

https://github.com/facebook/lexical/pull/6629

github-actions[bot] commented 1 month ago

🚀 This is included in version v3.0.0-beta.110

github-actions[bot] commented 1 month ago

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.