You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And then try to return to Lexical mode - note the nested quote is not rendered properly and looks like:
Hello
> Hello, nice to meet you
Here's how it looks e.g. in Github's markdown (and every other MD editor I've used):
Hello
Hello, nice to meet you
Impact of fix
I used quotes as an example above, but even writing this issue in the current format would not be possible in Lexical. Here I use a code block nested in a list, quotes nested in a list, and the example of quotes nested in quotes - none of these exist in Lexical's markdown. See also the Related Issues below.
For export, it seems to me there's a simple solution of making exportTopLevelElements in https://github.com/facebook/lexical/blob/main/packages/lexical-markdown/src/MarkdownExport.ts truly recursive - that is it passes itself instead of exportChildren in the inner loop of handling ElementTransformers (or as an extra param if we're worried about breaking existing cases). Lists already need to call back into themselves recursively to support nesting, but it's silly to assume an element should handle all possible nested children manually.
For import, I need to experiment more, but I think in $importBlocks it might work to pass $importBlocks itself to the replace function in https://github.com/facebook/lexical/blob/main/packages/lexical-markdown/src/MarkdownImport.ts. This probably also needs to happen for multiline importing, as a very common case would be to import the lines between the start match and end match as normal and just have that as a nested child (e.g. this is how you'd handle a markdown implementation of the Playground's "Collapsible Container" element).
I Just want to make sure there's no support here that I'm not aware of before I send a PR to support some of these cases.
Related Issues
There are some other issues with Markdown operations that I'm not sure are accidental or desired for some reason, but are quite unintuitive:
Shadow Roots are essentially unsupported, as nothing under a shadow root will get exported using ElementTransformers.
Exporting using $convertToMarkdownString can give totally different results depending on what node is passed - ElementTransformers will only be called for children of the node passed, not the node passed, and not any descendents besides direct children. This makes the export essentially invalid unless the passed node is a root or shadow root. If that's intended, a check for $isRootOrShadowRoot should be added.
Exporting using $convertToMarkdownString and passing a node actually only exports the node's children, not the node itself. For example passing a ListNode will give non-list output Markdown as it only exports the ListItemNode children - which have no transformer themselves and thus only their raw text content will be exported.
When exporting using $convertToMarkdownString, TextMatchTransformers are never run on the first two levels of ElementNodes. This means, for example, trying to export a ParagraphNode with a child LinkNode will fail, only the link's display text will be present.
The text was updated successfully, but these errors were encountered:
Lexical version: v0.23.1+dev.esm (using Playground)
Steps To Reproduce
Enter playground
Enter markdown mode and type:
And then try to return to Lexical mode - note the nested quote is not rendered properly and looks like:
Here's how it looks e.g. in Github's markdown (and every other MD editor I've used):
Impact of fix
I used quotes as an example above, but even writing this issue in the current format would not be possible in Lexical. Here I use a code block nested in a list, quotes nested in a list, and the example of quotes nested in quotes - none of these exist in Lexical's markdown. See also the Related Issues below.
For export, it seems to me there's a simple solution of making
exportTopLevelElements
in https://github.com/facebook/lexical/blob/main/packages/lexical-markdown/src/MarkdownExport.ts truly recursive - that is it passes itself instead ofexportChildren
in the inner loop of handlingElementTransformers
(or as an extra param if we're worried about breaking existing cases). Lists already need to call back into themselves recursively to support nesting, but it's silly to assume an element should handle all possible nested children manually.For import, I need to experiment more, but I think in
$importBlocks
it might work to pass$importBlocks
itself to thereplace
function in https://github.com/facebook/lexical/blob/main/packages/lexical-markdown/src/MarkdownImport.ts. This probably also needs to happen for multiline importing, as a very common case would be to import the lines between the start match and end match as normal and just have that as a nested child (e.g. this is how you'd handle a markdown implementation of the Playground's "Collapsible Container" element).I Just want to make sure there's no support here that I'm not aware of before I send a PR to support some of these cases.
Related Issues
There are some other issues with Markdown operations that I'm not sure are accidental or desired for some reason, but are quite unintuitive:
ElementTransformer
s.$convertToMarkdownString
can give totally different results depending on what node is passed -ElementTransformer
s will only be called for children of the node passed, not the node passed, and not any descendents besides direct children. This makes the export essentially invalid unless the passed node is a root or shadow root. If that's intended, a check for$isRootOrShadowRoot
should be added.$convertToMarkdownString
and passing a node actually only exports the node's children, not the node itself. For example passing aListNode
will give non-list output Markdown as it only exports theListItemNode
children - which have no transformer themselves and thus only their raw text content will be exported.$convertToMarkdownString
,TextMatchTransformer
s are never run on the first two levels ofElementNode
s. This means, for example, trying to export aParagraphNode
with a childLinkNode
will fail, only the link's display text will be present.The text was updated successfully, but these errors were encountered: