mdx-js / mdx

Markdown for the component era
https://mdxjs.com
MIT License
17.77k stars 1.14k forks source link

remark-mdx crashes on "<" #2264

Closed leo-petrucci closed 1 year ago

leo-petrucci commented 1 year ago

Initial checklist

Affected packages and versions

remark-mdx@2.3.0

Link to runnable example

https://codesandbox.io/s/remark-mdx-issue-196smb?file=/src/index.js

Steps to reproduce

I'm trying to parse MDX from an editor, but I've encountered an issue whenever I try to type the character "<". The MDX parser thinks it's the start of a component and crashes the entire thing.

Expected behavior

I think the "<" should ideally be escaped like what happens when it's not placed at the end of the file:

1 < 2 -> 1 /< 2

Actual behavior

The parser throws an error and crashes.

Runtime

Node v16

Package manager

yarn v3

OS

macOS

Build and bundle tools

webpack

wooorm commented 1 year ago

This is very much intentional. Have you tried typing a < somewhere in a javascript file? It crashes. Why should mdx behave differently?

(And I believe the example you show in expected behavior works fine: < plus a space is allowed)

leo-petrucci commented 1 year ago

@wooorm That's fair enough.

Do you have any advice if I was trying to parse a larger Markdown string that might end with a "<"? Any way for remark-mdx to ignore that single character?

wooorm commented 1 year ago

The advise is explained in the article on “What is MDX?” and Troubleshooting. Write MDX, which means in this case: handle <. By escaping it: \<.