Last active
May 7, 2019 09:55
-
-
Save felipeleusin/55fd135b017868965043c46f9ae7b054 to your computer and use it in GitHub Desktop.
Code JSX
This file contains hidden or 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 Highlight, { defaultProps } from 'prism-react-renderer'; | |
import prismTheme from 'prism-react-renderer/themes/duotoneDark'; | |
/* Use like | |
<Code>{` | |
var foo = "blah"; | |
`}</Code> | |
or | |
<Code code={myCodeString} /> | |
*/ | |
export const Code = ({ code, children }) => ( | |
<Highlight | |
theme={prismTheme} | |
code={code || children} | |
language="typescript" | |
> | |
{({ className, style, tokens, getLineProps, getTokenProps }) => ( | |
<pre className={className} style={style}> | |
{tokens.map((line, i) => ( | |
<div key="fake-key" {...getLineProps({ line, key: i })}> | |
{line.map((token, key) => ( | |
<span key="fake-key" {...getTokenProps({ token, key })} /> | |
))} | |
</div> | |
))} | |
</pre> | |
)} | |
</Highlight> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment