@@ -43,6 +43,11 @@ export const InlineCode = styled.code`
43
43
background-color: ${ themeGet ( 'colors.neutral.muted' ) } ;
44
44
border-radius: ${ themeGet ( 'radii.2' ) } ;
45
45
`
46
+ const colorMap = {
47
+ 'token comment' : '#747458' ,
48
+ 'token parameter variable' : '#277d7b' ,
49
+ 'token function' : '#cf3846' ,
50
+ }
46
51
47
52
const MonoText = props => < Text sx = { { fontFamily : 'mono' , fontSize : 1 } } { ...props } />
48
53
@@ -91,16 +96,6 @@ const CodeBlock = ({children, code, className, style}) => (
91
96
</ Box >
92
97
)
93
98
94
- function getCustomTokenStyle ( { className, style} ) {
95
- const colorMap = {
96
- 'token comment' : '#747458' ,
97
- 'token parameter variable' : '#277d7b' ,
98
- 'token function' : '#cf3846' ,
99
- }
100
-
101
- return colorMap [ className ] ? { ...style , color : colorMap [ className ] } : style
102
- }
103
-
104
99
function Code ( { className = '' , prompt, children} ) {
105
100
if ( prompt ) {
106
101
return (
@@ -125,7 +120,10 @@ function Code({className = '', prompt, children}) {
125
120
< Box key = { i } { ...getLineProps ( { line, key : i } ) } >
126
121
{ line . map ( ( token , key ) => {
127
122
const tokenProps = getTokenProps ( { token, key} )
128
- const tokenStyle = getCustomTokenStyle ( tokenProps )
123
+ const tokenStyle = colorMap [ tokenProps . className ]
124
+ ? { ...tokenProps . style , color : colorMap [ tokenProps . className ] }
125
+ : tokenProps . style
126
+
129
127
return < MonoText key = { key } { ...tokenProps } style = { tokenStyle } />
130
128
} ) }
131
129
</ Box >
0 commit comments