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

deserialiseMd created an invalid TElement array #2173

Closed
naorzr opened this issue Jan 30, 2023 · 4 comments · Fixed by #2175
Closed

deserialiseMd created an invalid TElement array #2173

naorzr opened this issue Jan 30, 2023 · 4 comments · Fixed by #2175
Assignees
Labels
bug Something isn't working plugin:deserializer-md Markdown deserializer remark-slate

Comments

@naorzr
Copy link

naorzr commented Jan 30, 2023

Description

when trying to deserialise markdown, the function produces invalid TElement array structure that results in
Cannot read properties of undefined (reading 'map') error.

it seems like it breaks with images, it converts them to nodes that contain caption and link instead of url.
the caption part seems to be the breaking part.

example:


{
    "type": "img",
    "children": [
        {
            "text": ""
        }
    ],
    "link": "https://sampleurl.com/8b0a-2c3b0f0f3e3e.png",
    "caption": "image"
}

Steps

  1. go to https://platejs.org
  2. paste the markdown from the example https://markdown-it.github.io/

Funding

  • You can sponsor this specific effort via a Polar.sh pledge below
  • We receive the pledge once the issue is completed & verified
Fund with Polar
@naorzr naorzr added the bug Something isn't working label Jan 30, 2023
@12joan 12joan added the plugin:deserializer-md Markdown deserializer label Jan 30, 2023
@12joan
Copy link
Collaborator

12joan commented Jan 30, 2023

Thanks for the bug report!

As you say, pasting an image is enough to cause the error. There's a slightly different error message if the alt text is empty.

![Minion](https://octodex.github.com/images/minion.png)
![](https://octodex.github.com/images/minion.png)

@12joan
Copy link
Collaborator

12joan commented Jan 30, 2023

There are a few issues on remark-slate, the package used by Plate to convert markdown to Slate nodes, relating to this problem. See #44, for example.

Ideally, the configuration in Plate should work out of the box. We might need to open a PR on remark-slate to add the configuration options necessary for that.

I've tested PR #45, which fixes the error but still produces an invalid image node.

@12joan
Copy link
Collaborator

12joan commented Jan 30, 2023

PR #45 combined with imageSourceKey: 'url' is enough to produce a valid image. The only weird thing is it's added as a child of a paragraph node. @zbeyens Is this a problem?

Node produced by HTML deserializer
  {
    "type": "img",
    "url": "https://octodex.github.com/images/minion.png",
    "children": [
      {
        "text": ""
      }
    ]
  },
Node produced by markdown deserializer
  {
    "type": "p",
    "children": [
      {
        "type": "img",
        "children": [
          {
            "text": ""
          }
        ],
        "url": "https://octodex.github.com/images/minion.png",
        "caption": [
          {
            "text": "Minion"
          }
        ]
      }
    ]
  }

@zbeyens
Copy link
Member

zbeyens commented Jan 30, 2023

@12joan It looks like remark-slate author is inactive – one PR has been open for a year now. Let's fork its src into the deserializer-md package.

img should not be inside a p: this is valid only for inline images. Let's make it a block by default, and support inline with an option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working plugin:deserializer-md Markdown deserializer remark-slate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants