# react-codemirror-runmode

> Syntax highlighting for react, utilizing CodeMirror's parser

Latest version **2.4.0** (published 2026-07-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-codemirror-runmode
pnpm add react-codemirror-runmode
yarn add react-codemirror-runmode
bun add react-codemirror-runmode
```

## Health

**Score 55/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.4.0 |
| Published | 2026-07-26 |
| First published | 2017-10-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 919.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Author | Takuya Matsuyama <hi@craftz.dog> |
| Maintainers | craftzdog |
| Keywords | codemirror, highlight, react, syntax |

## Links

- npm: https://www.npmjs.com/package/react-codemirror-runmode
- Repository: https://github.com/craftzdog/react-codemirror-runmode
- npm.io page: https://npm.io/package/react-codemirror-runmode

## Dependencies (5)

- [@lezer/common](https://npm.io/package/@lezer/common.md) ^1.5.2
- [@lezer/highlight](https://npm.io/package/@lezer/highlight.md) ^1.2.3
- [@codemirror/language](https://npm.io/package/@codemirror/language.md) ^6.12.4
- [@codemirror/lang-markdown](https://npm.io/package/@codemirror/lang-markdown.md) ^6.5.1
- [@codemirror/language-data](https://npm.io/package/@codemirror/language-data.md) ^6.5.2

## Alternatives

- [@oh-my-pi/pi-natives](https://npm.io/package/@oh-my-pi/pi-natives.md) — 51.8K weekly downloads
- [@capgo/capacitor-light-sensor](https://npm.io/package/@capgo/capacitor-light-sensor.md) — 3.0K weekly downloads
- [@heyhuynhgiabuu/pi-diff](https://npm.io/package/@heyhuynhgiabuu/pi-diff.md) — 492 weekly downloads
- [@lotsa/verdant-lang-asm](https://npm.io/package/@lotsa/verdant-lang-asm.md) — 38 weekly downloads
- [new-era-syntax](https://npm.io/package/new-era-syntax.md) — 20 weekly downloads

## Recent versions

- 2.4.0 (latest) — 2026-07-26
- 2.3.0 — 2026-06-23
- 2.2.1 — 2025-12-12
- 2.2.0 — 2025-12-12
- 2.1.0 — 2025-05-14
- 2.0.2 — 2025-03-21
- 2.0.1 — 2024-05-10
- 2.0.0 — 2024-05-10
- 1.0.5 — 2019-08-02
- 1.0.4 — 2017-12-14
- 1.0.3 — 2017-10-10
- 1.0.2 — 2017-10-10
- 1.0.1 — 2017-10-10
- 1.0.0 — 2017-10-10

## README

# react-codemirror-runmode

Syntax highlighter for React, using CodeMirror 6.
It automatically loads [the language metadata](https://github.com/codemirror/language-data) and dynamically loads language parser modules based on the specified language.

## Installation

```sh
npm install --save react-codemirror-runmode
```

## Usage

```javascript
import { oneDarkHighlightStyle } from '@codemirror/theme-one-dark'
import { Highlighter } from 'react-codemirror-runmode'
import React from 'react'
import ReactDOM from 'react-dom/client'

const code = 'const x = 123'

ReactDOM.createRoot(document.getElementById('app')!).render(
  <Highlighter lang="js" theme={oneDarkHighlightStyle}>
    {code}
  </Highlighter>
)
```

## Theming

You can apply custom themes using CodeMirror's theme system. This component uses [`HighlightStyle`](https://codemirror.net/docs/ref#language.HighlightStyle) objects to apply styles, which you can customize or replace.

## Reference

### `Highlighter`

Props:

- `lang`: `string` - The name of the language
- `theme`: [`Highlighter`](https://lezer.codemirror.net/docs/ref/#highlight.Highlighter)` | readonly Highlighter[]` - The highlight style. Pass an array to combine several highlighters; their emitted classes are merged per token (e.g. a generic token theme plus a markdown-specific one).
- `children`: `string` - The code to highlight
- `fallbackLanguage`: `Language` - Optional fallback language to use if the specified language isn't found
- `languages`: `LanguageDescription[]` - Optional custom list of language descriptions
- `markdownConfig`: `MarkdownConfig` - Optional markdown parser options, applied only when `lang` is `markdown`/`md`. See [Markdown highlighting](#markdown-highlighting).

### `highlightCode<o>(languageName, input, highlighter, fallbackLanguage?, languages?, callback, markdownConfig?): Promise<Output[]>`

Parameters:

- `languageName`: `string` - The name of the language
- `input`: `string` - The code to highlight
- `highlighter`: [`Highlighter`](https://lezer.codemirror.net/docs/ref/#highlight.Highlighter)` | readonly Highlighter[]` - The highlight style, or an array of styles whose classes are merged
- `fallbackLanguage`: `Language` - Optional fallback language to use if the specified language isn't found
- `languages`: `LanguageDescription[]` - Optional custom list of language descriptions
- `callback`: `(text: string, style: string | null, from: number, to: number) => Output)` - A callback function that converts the parsed tokens
- `markdownConfig`: `MarkdownConfig` - Optional markdown parser options, applied only when `languageName` is `markdown`/`md`

### `getCodeParser(input, languageName, fallbackLanguage?, languages?, markdownConfig?): Promise<Parser | null>`

Parameters:

- `input`: `string` - The code to highlight (used to preload nested code-fence languages for markdown)
- `languageName`: `string` - The name of the language
- `fallbackLanguage?`: `Language` - A fallback language (Optional)
- `languages?`: `LanguageDescription[]` - Optional custom list of language descriptions
- `markdownConfig?`: `MarkdownConfig` - Optional markdown parser options, applied only when `languageName` is `markdown`/`md`

## Markdown highlighting

When `lang` is `markdown` (or `md`), the markdown source is parsed with
[`@codemirror/lang-markdown`](https://github.com/codemirror/lang-markdown). By default this
uses a **CommonMark** base with no extensions. Pass `markdownConfig` to opt into GFM and/or
custom [Lezer markdown extensions](https://github.com/lezer-parser/markdown#user-content-markdownextension):

```javascript
import { Highlighter } from 'react-codemirror-runmode'
import { markdownLanguage } from '@codemirror/lang-markdown'

// GFM (tables, strikethrough, task lists, autolinks) + custom extensions,
// with two highlighters whose classes are merged per token.
;<Highlighter
  lang="markdown"
  theme={[tokenHighlighter, mdTokenHighlighter]}
  markdownConfig={{
    base: markdownLanguage,
    extensions: [/* your @lezer/markdown extensions */]
  }}
>
  {markdownSource}
</Highlighter>
```

`MarkdownConfig` mirrors the `base` and `extensions` options of `markdown()`. Prefer a stable
reference for `markdownConfig` (e.g. a module-level constant) to avoid re-highlighting on every
render.

## License

MIT License. Developed by Takuya Matsuyama <hi@craftz.dog>

---
_Source: https://npm.io/package/react-codemirror-runmode · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
