A library of custom themes for CodeMirror 6.
@fsegurai/codemirror-theme-bundle is a collection of themes to enhance CodeMirror 6 editor, making it visually
engaging and adaptable to different coding styles and user preferences.
To add @fsegurai/codemirror-theme-bundle along with CodeMirror 6 to your package.json use the following commands.
bun install @fsegurai/codemirror-theme-bundle codemirror@^6.0.0 --saveImport the desired theme from the package and apply it to your CodeMirror instance as shown below.
import {EditorView, basicSetup} from 'codemirror'
import {markdown} from '@codemirror/lang-markdown'
import {bundle} from '@fsegurai/codemirror-theme-bundle'
let editor = new EditorView({
doc: '# Hello World',
extensions: [
basicSetup,
markdown(),
bundle
],
parent: document.body
})Every theme package depends on @fsegurai/codemirror-theme-core (installed automatically). Without a bundler (import
maps, CDN), map the core too: the theme builds import it.
Read the CodeMirror documentation for more details about themes. The
versioned documentation of this release is in docs/6.32.0.
Every theme is built by @fsegurai/codemirror-theme-core, which every theme package
depends on. It is public, so a theme of your own gets the same complete structure:
defineTheme(definition)turns aThemeDefinition(a completeUiPaletteplus syntax roles) into{ extension, theme, highlightStyle, mergeStyles }.cssVariableTheme(options?)is one theme whose colors are CSS custom properties with fallbacks (var(--cm-background, #ffffff),var(--cm-syntax-keyword, #cf222e), …), so a single extension follows the page's light, dark or high-contrast CSS. Pass{ dark: true }on dark pages (CSS variables cannot tell CodeMirror the editor is dark),prefixto rename the variables andvariables/fallbacksto map them to your own tokens.
import { cssVariableTheme } from '@fsegurai/codemirror-theme-core';
const extensions = [basicSetup, cssVariableTheme({ dark: false }).extension];:root { --cm-background: var(--app-surface); --cm-foreground: var(--app-text); --cm-accent: var(--app-primary); }The core README lists every variable it reads (14 base colors, then per-part and
per-syntax-role overrides), its options, and an Angular example. Both functions are also exported by
@fsegurai/codemirror-theme-bundle.
To see all themes in action, check out the demo: https://fsegurai.github.io/codemirror-themes.
To set up the demo locally:
git clone https://github.com/fsegurai/codemirror-themes.git
bun install
bun startThis will serve the application locally at http://[::1]:8000.
Licensed under MIT.
