mdx-js / mdx

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

mdx 3 converts component elements to p tag #2408

Closed Heet-Bhalodiya closed 10 months ago

Heet-Bhalodiya commented 10 months ago

Initial checklist

Affected packages and versions

v3.0.0

Link to runnable example

No response

Steps to reproduce

I am using node v20.9.0

<Typography>
  Please refer to MUI&#39;s official docs for more details on component&#39;s{' '}
  <Link href='https://mui.com/material-ui/react-alert/' target='_blank' rel='noopener noreferrer' className='no-underline'>
    usage guide
  </Link>{' '}
  and{' '}
  <Link href='https://mui.com/material-ui/react-alert/#api' target='_blank' rel='noopener noreferrer' className='no-underline'>
    API documentation
  </Link>
  .
</Typography>

using above code in mdx file I am getting following errors which was not there in the mdx version 2.

image

Expected behavior

Screenshot 2023-11-27 at 5 11 53 PM

Screenshot 2023-11-27 at 5 10 19 PM

Actual behavior

mdx 3 converts component elements to p tag which lead to <p> cannot appear as a descendant of <p> error

image

image

Runtime

Other (please specify in steps to reproduce)

Package manager

pnpm

OS

macOS

Build and bundle tools

Docusaurus

wooorm commented 10 months ago

You can search through closed issues or read the docs. Such as: https://mdxjs.com/docs/what-is-mdx/#interleaving.

Heet-Bhalodiya commented 10 months ago

Hello @wooorm,

I am using multiline as I mentioned in above code that I am using Link component inside Typography. So I can't write all these code in one line. So what should I do now?

remcohaszing commented 10 months ago

You can use an expression to use plain JSX instead of MDX.

{
<Typography>
  Please refer to MUI&#39;s official docs for more details on component&#39;s{' '}
  <Link href='https://mui.com/material-ui/react-alert/' target='_blank' rel='noopener noreferrer' className='no-underline'>
    usage guide
  </Link>{' '}
  and{' '}
  <Link href='https://mui.com/material-ui/react-alert/#api' target='_blank' rel='noopener noreferrer' className='no-underline'>
    API documentation
  </Link>
  .
</Typography>
}
wooorm commented 10 months ago

So I can't write all these code in one line.

It doesn’t have to be on one line. That’s not what the text says. For example:

<Typography>Please refer to MUI’s official docs for more
details on component’s <Link href='https://mui.com/material-ui/react-alert/'
target='_blank' rel='noopener noreferrer' className='no-underline'>usage guide
</Link> and <Link href='https://mui.com/material-ui/react-alert/#api'
target='_blank' rel='noopener noreferrer' className='no-underline'> API
documentation</Link>.</Typography>