Created
December 15, 2021 19:50
-
-
Save PavlikPolivka/16b54c966a3c15ae4312f71066e5702d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ReactMarkdown from 'react-markdown'; | |
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; | |
import { materialDark } from "react-syntax-highlighter/dist/cjs/styles/prism"; | |
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch"; | |
<ReactMarkdown | |
components={{ | |
p: ({ node, children }) => { | |
if (node.children[0].tagName === "img") { | |
const image = node.children[0]; | |
return ( | |
<TransformWrapper> | |
<TransformComponent> | |
<img | |
alt={image.properties.alt} | |
src={`${image.properties.src}`} | |
/> | |
</TransformComponent> | |
</TransformWrapper> | |
); | |
} | |
// Return default child if it's not an image | |
return <p>{children}</p>; | |
}, | |
code({ className, children }) { | |
// Removing "language-" because React-Markdown already added "language-" | |
let language = ""; | |
if (className) { | |
language = className.replace("language-", ""); | |
} | |
return ( | |
<SyntaxHighlighter | |
style={materialDark} | |
language={language} | |
children={children[0]} | |
/> | |
); | |
}, | |
}} | |
> | |
{postData.contentMarkdown} | |
</ReactMarkdown> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment