Skip to content

Commit e6fe620

Browse files
committed
Refactor code.js to improve syntax highlighting colors
1 parent b19fcc2 commit e6fe620

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/mdx/code.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ const CodeBlock = ({children, code, className, style}) => (
9191
</Box>
9292
)
9393

94+
function getCustomTokenStyle(tokenProps) {
95+
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+
default:
102+
return style
103+
}
104+
}
105+
94106
function Code({className = '', prompt, children}) {
95107
if (prompt) {
96108
return (
@@ -115,9 +127,7 @@ function Code({className = '', prompt, children}) {
115127
<Box key={i} {...getLineProps({line, key: i})}>
116128
{line.map((token, key) => {
117129
const tokenProps = getTokenProps({token, key})
118-
const tokenStyle =
119-
tokenProps.className === 'token comment' ? {...tokenProps.style, color: '#747458'} : tokenProps.style
120-
130+
const tokenStyle = getCustomTokenStyle(tokenProps)
121131
return <MonoText key={key} {...tokenProps} style={tokenStyle} />
122132
})}
123133
</Box>

0 commit comments

Comments
 (0)