Socket
Book a DemoInstallSign in
Socket

@codemirror/language

Package Overview
Dependencies
Maintainers
2
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codemirror/language

Language support infrastructure for the CodeMirror code editor

latest
Source
npmnpm
Version
6.11.3
Version published
Weekly downloads
3.2M
-0.01%
Maintainers
2
Weekly downloads
 
Created
Source

@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))

Keywords

editor

FAQs

Package last updated on 15 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts