Closed AlessioGr closed 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.
ok, a second attempt was necessary, but now it is merged
🚀 This is included in version v3.0.0-beta.110
This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.
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