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
38
39
40
41
42
|
/**
* @prettier
*/
import React from "react"
import PropTypes from "prop-types"
import ReactSyntaxHighlighter from "react-syntax-highlighter/dist/esm/light"
const SyntaxHighlighter = ({
language,
className = "",
getConfigs,
syntaxHighlighting = {},
children = "",
}) => {
const theme = getConfigs().syntaxHighlight.theme
const { styles, defaultStyle } = syntaxHighlighting
const style = styles?.[theme] ?? defaultStyle
return (
<ReactSyntaxHighlighter
language={language}
className={className}
style={style}
>
{children}
</ReactSyntaxHighlighter>
)
}
SyntaxHighlighter.propTypes = {
language: PropTypes.string.isRequired,
className: PropTypes.string,
getConfigs: PropTypes.func.isRequired,
syntaxHighlighting: PropTypes.shape({
styles: PropTypes.object,
defaultStyle: PropTypes.object,
}),
renderPlainText: PropTypes.func,
children: PropTypes.string,
}
export default SyntaxHighlighter
|