Reamrk- components code block not rendering... #1156
-
const customRenderers = {
code({ language, value }) {
return (
<SyntaxHighlighter language={language} style={atomDark}>
{value}
</SyntaxHighlighter>
);
},
};
<ReactMarkdown
className={classes.markdownContent}
components={customRenderers}
children={content}
/> All though every other content is showing up but the code block is empty What could have gone wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Welcome @AbhayaShankar! A good starter would be following the example in the import React from 'react'
import ReactDom from 'react-dom'
import ReactMarkdown from 'react-markdown'
import {Prism as SyntaxHighlighter} from 'react-syntax-highlighter'
import {dark} from 'react-syntax-highlighter/dist/esm/styles/prism'
// Did you know you can use tildes instead of backticks for code in markdown? ✨
const markdown = `Here is some JavaScript code:
~~~js
console.log('It works!')
~~~
`
ReactDom.render(
<ReactMarkdown
children={markdown}
components={{
code({node, inline, className, children, ...props}) {
const match = /language-(\w+)/.exec(className || '')
return !inline && match ? (
<SyntaxHighlighter
{...props}
children={String(children).replace(/\n$/, '')}
style={dark}
language={match[1]}
PreTag="div"
/>
) : (
<code {...props} className={className}>
{children}
</code>
)
}
}}
/>,
document.body
) If the issue persists, consider sharing a reproducible example of what you are seeing. |
Beta Was this translation helpful? Give feedback.
That still is missing a fair bit of detail, aim to create a minimal reproducible example https://stackoverflow.com/help/minimal-reproducible-example
and share it using a sandbox like https://next.new
In the absence of that.
It sounds like you are trying to do server side rendering with Next js + server components?
If so, you are likely running into an issue in the syntax highlighter itself, such as react-syntax-highlighter/react-syntax-highlighter#493, react-syntax-highlighter/react-syntax-highlighter#263 (comment), react-syntax-highlighter/react-syntax-highlighter#509
Next seems to recommend using
prism
for syntax highlighting markdown code block in SSR mode https://nextjs.org/blog/mark…