Skip to content

Instantly share code, notes, and snippets.

@felipeleusin
Last active May 7, 2019 09:55
Show Gist options
  • Save felipeleusin/55fd135b017868965043c46f9ae7b054 to your computer and use it in GitHub Desktop.
Save felipeleusin/55fd135b017868965043c46f9ae7b054 to your computer and use it in GitHub Desktop.
Code JSX
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