mdx-editor / editor

A rich text editor React component for markdown
https://mdxeditor.dev
MIT License
1.65k stars 133 forks source link

Errors on presumed MDX expression with curly braces #318

Open dave-db opened 6 months ago

dave-db commented 6 months ago

A string in {curly braces} within the body of a document is being parsed as an MDX expression, then throwing as there's no node handler for it. The same text content is processed ok by MDX evaluate/parse itself, so it looks like it relates to the conversion pipeline between markdown and Lexical.

Example content

Find your video at:

https://player.evideo.com/video?video-id={your-video-id}

> Replace `your-video-id` with your video id

The part in {curly braces} blew up the editor, but not the MDX processor (mdx-js evaluateSync), which rendered it fine unescaped. The editor error was:

Error: Cannot handle unknown node `mdxTextExpression`
    at Object.unknown (webpack-internal:///(:3000/admin/app-pages-browser)/./node_modules/@mdxeditor/editor/node_modules/mdast-util-to-markdown/lib/index.js:120:11)
    at Object.one [as handle] (webpack-internal:///(:3000/admin/app-pages-browser)/./node_modules/zwitch/index.js:112:17)
    at toMarkdown (webpack-internal:///(:3000/admin/app-pages-browser)/./node_modules/@mdxeditor/editor/node_modules/mdast-util-to-markdown/lib/index.js:85:24)
    at visit (webpack-internal:///(:3000/admin/app-pages-browser)/./node_modules/@mdxeditor/editor/dist/importMarkdownToLexical.js:78:156)
    at eval (webpack-internal:///(:3000/admin/app-pages-browser)/./node_modules/@mdxeditor/editor/dist/importMarkdownToLexical.js:68:45)

Originally posted by @dave-db in https://github.com/mdx-editor/editor/discussions/312#discussioncomment-8171127

petyosi commented 6 months ago

Thank you, I will test that. To ensure I'm not missing something, in that case, you would rather not have any special processing of the {your-video-id} token, right?

dave-db commented 6 months ago

Yup, absolutely - it should be just string content in the link (in this case). Looking at the docs for mdast-util-mdx-expression, I think the whitespace around braces should be treated as significant, although I'm not clear on exactly what the spec is. mdx-js itself doesn't try to parse it (at least in my pipeline), so maybe I don't have that plugin enabled for rendering pages?