A react component for making source-code snippets prettier using Google's code-prettify.
import Code from 'react-code-prettify';
const codeString = `function map(f, a) {
var result = [], // Create a new Array
i;
for (i = 0; i != a.length; i++)
result[i] = f(a[i]);
return result;
};`
<Code
codeString={example1}
language="javascript"
/>
Required prop. Need to be the string of code that you want to pretify and highlight.
Optional prop. You don't need to specify the language since it will automatically guess. Still you can specify a language by passing it in this props.
- Thanks to the contributors of code-prettify and Google.
- Thanks to Alex Milanov for npm fork of
code-prettify
. - Thanks to Max Stoiber for styled-components 💅