Skip to content

Language presets

The curated language-preset catalog for <CodeMirror>, shipped by every leaf package under the /languages subpath.

The base CodeMirror import bundles exactly one language (JavaScript) so the import stays lean. For everything else, each leaf ships curated language presets via a /languages subpath — ready-to-spread Extension[] constants you drop into :extensions for a robust syntax-highlighting starting point on a common use case. The base component and the language prop are unchanged; presets are a purely additive opt-in.

ts
import { CodeMirror } from '@rozie-ui/codemirror-react';
import { web } from '@rozie-ui/codemirror-react/languages';
// <CodeMirror :extensions={web} />   // HTML + embedded CSS/JS
vue
<script setup lang="ts">
import { ref } from 'vue';
import CodeMirror from '@rozie-ui/codemirror-vue';
import { python } from '@rozie-ui/codemirror-vue/languages';

const value = ref('def greet():\n    return "hello"\n');
</script>

<template>
  <CodeMirror v-model:value="value" :extensions="python" />
</template>

Catalog — each preset is an Extension[]; the right column lists the @codemirror/lang-* package it pulls into your bundle:

PresetWhat it highlightsPulls
web (alias html)HTML with auto-embedded CSS + JavaScript@codemirror/lang-html (+ lang-css, lang-javascript transitively)
cssPlain CSS@codemirror/lang-css
scssSCSS (sass({ indented: false }))@codemirror/lang-sass
sassIndented Sass syntax@codemirror/lang-sass
vueVue SFC + SCSS <style lang="scss">@codemirror/lang-vue, @codemirror/lang-sass
javascriptJavaScript@codemirror/lang-javascript
typescriptTypeScript@codemirror/lang-javascript
jsxJavaScript + JSX@codemirror/lang-javascript
tsxTypeScript + JSX@codemirror/lang-javascript
jsonJSON@codemirror/lang-json
markdownMarkdown@codemirror/lang-markdown
yamlYAML@codemirror/lang-yaml
xmlXML@codemirror/lang-xml
pythonPython@codemirror/lang-python
sqlSQL@codemirror/lang-sql

Tree-shakable by design. CodeMirror language constructors are pure (no global registration), so the presets are side-effect-free eager exports: a consumer importing only { web } pulls only @codemirror/lang-html (and the CSS/JS it embeds) — python/sql/yaml/the rest are dropped by your bundler. The base CodeMirror import carries none of them.

Raw constructors for power users. Compose your own arrays from the raw @codemirror/lang-* constructors, re-exported under a lang namespace object:

ts
import { lang } from '@rozie-ui/codemirror-react/languages';
const extensions = [...lang.html(), myCustomExtension];

See also

Pre-1.0 — APIs may change between minor versions.