|
1 | 1 | import React, { useRef, useEffect } from 'react'; |
2 | 2 | import PropTypes from 'prop-types'; |
3 | | -import { makeStyles } from '@mui/styles'; |
| 3 | +import { Box } from '@mui/material'; |
4 | 4 | import Prism from 'prismjs'; |
5 | 5 | import 'prismjs-bibtex'; |
6 | 6 | import 'prismjs/themes/prism.css'; |
7 | 7 | import 'prismjs/themes/prism-okaidia.css'; // coy, dark, funky, okaidia, solarizedlight, tomorrow, twilight |
8 | 8 |
|
9 | | -const useStyles = makeStyles(() => ({ |
10 | | - code: { |
11 | | - fontSize: 10, |
12 | | - overflowWrap: 'break-word', |
13 | | - whiteSpace: 'pre-wrap', |
14 | | - } |
15 | | -})); |
16 | | - |
17 | 9 | function CodeHighlight({ code, language, className }) { |
18 | 10 | const codeNode = useRef(null); |
19 | | - const classes = useStyles(); |
20 | 11 |
|
21 | 12 | useEffect(() => { |
22 | | - // const code = codeNode.current.textContent; |
23 | 13 | if (Prism.languages.hasOwnProperty(language)) { |
24 | 14 | const highlightHTML = Prism.highlight(code, Prism.languages[language], language); |
25 | 15 | codeNode.current.innerHTML = highlightHTML; |
26 | 16 | } |
27 | 17 | }, [code, language]); |
28 | 18 |
|
29 | 19 | return ( |
30 | | - <pre className={className}> |
31 | | - <code ref={codeNode} className={classes.code}> |
| 20 | + <Box component="pre" className={className}> |
| 21 | + <Box |
| 22 | + component="code" |
| 23 | + ref={codeNode} |
| 24 | + sx={{ |
| 25 | + fontSize: 10, |
| 26 | + overflowWrap: 'break-word', |
| 27 | + whiteSpace: 'pre-wrap', |
| 28 | + }} |
| 29 | + > |
32 | 30 | { code } |
33 | | - </code> |
34 | | - </pre> |
| 31 | + </Box> |
| 32 | + </Box> |
35 | 33 | ); |
36 | 34 | } |
37 | 35 |
|
|
0 commit comments