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] Parsing of the following markdown structure failed: {"type":"code","name":"N/A"}. #370

Closed
floatrx opened this issue Feb 29, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@floatrx
Copy link

floatrx commented Feb 29, 2024

Description:
When using the MDXEditor in source mode and attempting to insert a code block using triple backticks (```), the editor fails to parse the markdown structure, resulting in a parsing error. This issue prevents users from adding code snippets to their markdown documents directly in the source mode.

Error Message:
Parsing of the following markdown structure failed: {"type":"code","name":"N/A"}. Steps to Reproduce:

Steps 2 reproduce

  • Open the MDXEditor.
  • Switch to source mode by selecting the "Source" option.
  • Attempt to insert a code block by typing or pasting in triple backticks followed by some code, then closing with triple backticks again.
    For example:
some code
  • Observe the parsing error message as described above.

Expected Behavior:
The editor should correctly parse the code block enclosed in triple backticks, allowing the user to insert code snippets into their markdown document without encountering a parsing error.

Actual Behavior:
The editor displays a parsing error when attempting to insert a code block using triple backticks, preventing the user from successfully adding code snippets in source mode.

@floatrx floatrx added the bug Something isn't working label Feb 29, 2024
@petyosi
Copy link
Contributor

petyosi commented Mar 1, 2024

My guess is that you need to configure the codeMirrorPlugin to support code blocks without any language specified, by passing a '': 'Text' to the codeBlockLanguages. Give it a try.

@floatrx
Copy link
Author

floatrx commented Mar 1, 2024

My guess is that you need to configure the codeMirrorPlugin to support code blocks without any language specified, by passing a '': 'Text' to the codeBlockLanguages. Give it a try.

I don't use the codeMirrorPlugin, and it's unnecessary for my purposes. Markdown inherently supports code blocks without the requirement to specify a language.

This bug was also reproduced in the official live demo
Screenshot 2024-03-01 at 17 16 57
Screenshot 2024-03-01 at 17 17 33

This issue is not critical but it would be nice to have it fixed.

@petyosi
Copy link
Contributor

petyosi commented Mar 1, 2024

Perhaps my response was not clear. The editor supports code blocks without a language, but you need to configure it so that it actually knows what kind of editor to associate with such a code block. I suggested the codeMirror one, but you can also use whatever you wish, the docs include an example with a text area.

@wp0403
Copy link

wp0403 commented Mar 3, 2024

I have encountered the same error as you, and need to configure all the code block languages you use in markdown to codeMirrorPlugin
image
image

@floatrx
Copy link
Author

floatrx commented Mar 3, 2024

@wp0403 Helps, but we should explicitly provide an empty string ('')

    const codeBlockLanguages = ['', ...]; // <- here                                           
    ...
    codeMirrorPlugin({
      codeBlockLanguages: codeBlockLanguages.reduce((acc, language) => {
        acc[language] = language;
        return acc;
      }, {}),
    }),```

@pbjorklund
Copy link

My guess is that you need to configure the codeMirrorPlugin to support code blocks without any language specified, by passing a '': 'Text' to the codeBlockLanguages. Give it a try.

This would be great to have in the example in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants