-
Notifications
You must be signed in to change notification settings - Fork 932
/
Copy pathCodeSnippet.js
37 lines (31 loc) · 953 Bytes
/
CodeSnippet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import prism from 'prismjs';
import 'prismjs/components/prism-jsx';
import 'prismjs/components/prism-bash';
import Paper from '@mui/material/Paper';
import { withStyles } from 'tss-react/mui';
const styles = theme => ({});
class CodeSnippet extends React.Component {
static propTypes = {
classes: PropTypes.object.isRequired,
language: PropTypes.string,
text: PropTypes.string.isRequired,
};
static defaultProps = {
language: 'jsx',
};
render() {
const { classes, language, text } = this.props;
const hightlightedCode = prism.highlight(text, prism.languages[language]);
return (
<Paper elevation={4}>
<pre>
<code className={`language-${language}`} dangerouslySetInnerHTML={{ __html: hightlightedCode }} />
</pre>
</Paper>
);
}
}
export default withStyles(CodeSnippet, styles);