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
No Difference between Code Block and inline code #244
Comments
Can confirm this is affecting my project too. If you don't use the ternary operator for the variable |
@thatanjan Try switching to: import CodeBlock from './CodeBlock'
const components = {}
components.pre = CodeBlock
export default components |
Note that MDX was upgraded to v2 as part of this, which was a breaking change and requires changes in how you author content. See the upgrade guide here: https://mdxjs.com/migrating/v2/#update-mdx-content Of note:
|
Finally, it is working. Thank you so much @BRKalow and @alexcarpenter. import CodeBlock from './CodeBlock'
const components = {}
components.pre = CodeBlock
export default components I also changed the prism code. Now it is getting the code from the nested import React from 'react'
import Highlight, { defaultProps } from 'prism-react-renderer'
import vsDark from 'prism-react-renderer/themes/vsDark'
const CodeBlock = ({ children }) => {
if (!children || children.type !== 'code') return null
const {
props: { className, children: code = '' },
} = children
const language = className ? className.replace(/language-/, '') : ''
return (
<Highlight
{...defaultProps}
theme={vsDark}
code={code.trim()}
language={language}
>
{({ className, style, tokens, getLineProps, getTokenProps }) => (
<pre className={className} style={{ ...style, padding: '20px' }}>
{tokens.map((line, i) => (
<div key={i} {...getLineProps({ line, key: i })}>
{line.map((token, key) => (
<span key={key} {...getTokenProps({ token, key })} />
))}
</div>
))}
</pre>
)}
</Highlight>
)
}
export default CodeBlock |
some notable changes - had to use `pre` for code blocks: hashicorp/next-mdx-remote#244 - had to force react version for mdxjs: PaulieScanlon/mdx-embed#237 - had to update mousetrail package to match react
I am using next-mdx-remote
4.0.0
version. When I try to add syntax highlights to code it doesn't distinguish between a code block and an inline code.I am using prism-react-renderer for syntax highlight with the following code.
My mdx code
MDX component object
Result
Expected Result
It works with the version
3.0.8
but not with the4.0.0
versionThanks in advance.
The text was updated successfully, but these errors were encountered: