Skip to content

Commit 539a92b

Browse files
committed
Refactor code.js to add support for custom token colors
1 parent 349e9f9 commit 539a92b

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/mdx/code.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,13 @@ const CodeBlock = ({children, code, className, style}) => (
9393

9494
function getCustomTokenStyle(tokenProps) {
9595
const {className, style} = tokenProps
96-
switch (className) {
97-
case 'token comment':
98-
return {...style, color: '#747458'}
99-
case 'token parameter variable':
100-
return {...style, color: '#277d7b'}
101-
case 'token function':
102-
return {...style, color: '#cf3846'}
103-
default:
104-
return style
96+
const colorMap = {
97+
'token comment': '#747458',
98+
'token parameter variable': '#277d7b',
99+
'token function': '#cf3846',
105100
}
101+
102+
return className in colorMap ? {...style, color: colorMap[className]} : style
106103
}
107104

108105
function Code({className = '', prompt, children}) {

0 commit comments

Comments
 (0)