@@ -43,6 +43,11 @@ export const InlineCode = styled.code`
4343 background-color: ${ themeGet ( 'colors.neutral.muted' ) } ;
4444 border-radius: ${ themeGet ( 'radii.2' ) } ;
4545`
46+ const colorMap = {
47+ 'token comment' : '#747458' ,
48+ 'token parameter variable' : '#277d7b' ,
49+ 'token function' : '#cf3846' ,
50+ }
4651
4752const MonoText = props => < Text sx = { { fontFamily : 'mono' , fontSize : 1 } } { ...props } />
4853
@@ -91,16 +96,6 @@ const CodeBlock = ({children, code, className, style}) => (
9196 </ Box >
9297)
9398
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-
10499function Code ( { className = '' , prompt, children} ) {
105100 if ( prompt ) {
106101 return (
@@ -125,7 +120,10 @@ function Code({className = '', prompt, children}) {
125120 < Box key = { i } { ...getLineProps ( { line, key : i } ) } >
126121 { line . map ( ( token , key ) => {
127122 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+
129127 return < MonoText key = { key } { ...tokenProps } style = { tokenStyle } />
130128 } ) }
131129 </ Box >
0 commit comments