Language support infrastructure for the CodeMirror code editor https://codemirror.net
  • TypeScript 100%
Find a file
2026-04-15 11:29:45 +02:00
src Update github links 2026-04-14 20:56:30 +02:00
test Revert "Support reconfiguration of an LRLanguage's language data" 2025-12-22 15:40:31 +01:00
.gitignore Move to @codemirror/buildhelper 2021-03-09 17:47:10 +01:00
.npmignore Tell TypeScript to not go through dist to load the package itself 2020-12-29 16:52:02 +01:00
CHANGELOG.md Mark version 6.12.3 2026-03-25 10:33:48 +01:00
LICENSE Update maintainer email 2023-01-24 08:20:07 +01:00
package.json Update github links 2026-04-14 20:56:30 +02:00
README.md Update github links 2026-04-14 20:56:30 +02:00

@codemirror/language NPM version

[ WEBSITE | DOCS | ISSUES | FORUM | CHANGELOG ]

This package implements the language support infrastructure for the CodeMirror code editor.

The project page has more information, a number of examples and the documentation.

This code is released under an MIT license.

We aim to be an inclusive, welcoming community. To make that explicit, we have a code of conduct that applies to communication around the project.

Usage

Setting up a language from a Lezer parser looks like this:

import {parser} from "@lezer/json"
import {LRLanguage, continuedIndent, indentNodeProp,
        foldNodeProp, foldInside} from "@codemirror/language"

export const jsonLanguage = LRLanguage.define({
  name: "json",
  parser: parser.configure({
    props: [
      indentNodeProp.add({
        Object: continuedIndent({except: /^\s*\}/}),
        Array: continuedIndent({except: /^\s*\]/})
      }),
      foldNodeProp.add({
        "Object Array": foldInside
      })
    ]
  }),
  languageData: {
    closeBrackets: {brackets: ["[", "{", '"']},
    indentOnInput: /^\s*[\}\]]$/
  }
})

Often, you'll also use this package just to access some specific language-related features, such as accessing the editor's syntax tree...

import {syntaxTree} from "@codemirror/language"

const tree = syntaxTree(view)

... or computing the appriate indentation at a given point.

import {getIndentation} from "@codemirror/language"

console.log(getIndentation(view.state, view.state.selection.main.head))