Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Nested Markdown Structures are Not Supported #7084

Open
jkjk822 opened this issue Jan 23, 2025 · 1 comment
Open

Bug: Nested Markdown Structures are Not Supported #7084

jkjk822 opened this issue Jan 23, 2025 · 1 comment
Labels
enhancement Improvement over existing feature markdown

Comments

@jkjk822
Copy link
Contributor

jkjk822 commented Jan 23, 2025

Lexical version: v0.23.1+dev.esm (using Playground)

Steps To Reproduce

  1. Enter playground

  2. Enter markdown mode and type:

    > Hello
    > > Hello, nice to meet you
    
  3. 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.
@alterhuman
Copy link

No support is present for this currently, you can send a PR.

@etrepum etrepum added enhancement Improvement over existing feature markdown labels Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement over existing feature markdown
Projects
None yet
Development

No branches or pull requests

3 participants