Styling CodeMirror blocks #930
Answered
by
cookesan
MrDiamondDog
asked this question in
Q&A
|
I would like to pick a theme for my CodeMirror blocks, as specified in https://codemirror.net/examples/styling/#themes. There doesn't seem to be anything exposed for this, and no documentation exists. All I could find was an old thread that wasn't helpful at all. Thanks! |
Answered by
cookesan
Apr 22, 2026
Replies: 1 comment
|
Use the import { EditorView } from '@codemirror/view'
codeMirrorPlugin({
codeBlockLanguages: { js: 'JavaScript', css: 'CSS' },
autoLoadLanguageSupport: true,
codeMirrorExtensions: [
EditorView.theme({
'&': {
backgroundColor: '#111827',
color: '#e5e7eb'
},
'.cm-gutters': {
backgroundColor: '#0f172a',
color: '#94a3b8'
}
})
]
})One caveat: MDXEditor's current |
0 replies
Answer selected by
MrDiamondDog
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use the
codeMirrorExtensionsoption. CodeMirror themes are extensions, so you can pass anEditorView.theme(...)extension throughcodeMirrorPlugin:One caveat: MDXEditor's current
CodeMirrorEditoralso adds its built-in light theme, so if you are overriding the same selectors you may need more specific …