[Bug] Crepe code block CSS overrides the default CodeMirror One Dark background
Initial checklist
- I agree to follow the code of conduct
- I searched issues and discussions and couldn’t find anything (or linked relevant results below)
Affected packages and versions
"@milkdown/crepe": "^7.22.1", "@milkdown/vue": "^7.22.1"
Link to runnable example
https://stackblitz.com/edit/crepe-coremirror-bug?file=src%2Fcomponents%2FMilkdownEditor.vue
Steps to reproduce
- Create a Crepe editor with the starter.
- Replace the markdown text in MilkdownEditor.vue by follow text:
const markdown = `\ \`\`\` def foo(): print('Hello Crepe') return \`\`\``; - Observe the code block in the preview on the right. Its background color is rendered incorrectly, as shown below:
- Add the following styles to change Crepe’s default styling to match the One Dark theme, which is the default CodeMirror theme used by Crepe. These styles are adapted from
@milkdown/crepe/theme/common/code-mirror.css<style> .milkdown .milkdown-code-block .cm-editor { background: #2d3139; } .milkdown .milkdown-code-block .cm-gutters { background: #2d3139; } </style> - Observe the code block in the preview on the right again. The styling now appears correctly, as shown below:
Expected behavior
The default CodeMirror One Dark theme should be applied consistently to the entire code editor, including:
- the editor background;
- the gutter background;
- the active line background.
The One Dark background should remain visible:
background-color: #282e34;Actual behavior
The CodeMirror One Dark theme is only partially applied.
The text and the first gutter colors use the One Dark theme, but the editor background is overridden by the Crepe rule.
This selector has higher specificity than the generated CodeMirror theme selector, so the One Dark background declaration is crossed out in DevTools.
As a result, the code block displays a light background with One Dark foreground colors instead of a consistent One Dark theme.
Runtime
Chrome
OS
Windows
Build and bundle tools
Vite
Source: Milkdown/milkdown