import ReactMarkdown from "react-markdown";
import { Content } from "mdast";
// import light build
import { PrismLight as SyntaxHighlighter } from "react-syntax-highlighter";
// import only whatever languages you are using. Thaw will dramatically reduce the build size of the page
import js from "react-syntax-highlighter/dist/cjs/languages/prism/javascript";
import python from "react-syntax-highlighter/dist/cjs/languages/prism/python";
// those tags are used when you write ```js {code here} ```
SyntaxHighlighter.registerLanguage("js", js);
SyntaxHighlighter.registerLanguage("py", python);
you define a custom renderer:
const customRenderers= {
// modify the code tag
code(code) {
// node since i use ts, this code here might vary in your app
const { node } = code;
const { lang, value } = node;
return (
<div style={{ fontSize: "1.6rem" }}>
<SyntaxHighlighter
style={vscDarkPlus}
language={lang}
children={value}
/>
</div>
);
},
};
after that return this component
return (
<article style={{ paddingLeft: "2rem" }}>
<ReactMarkdown renderers={customRenderers}>
// place whatever you want to render
{blog.content}
</ReactMarkdown>
</article>
)