Jinja language support for CodeMirror
  • TypeScript 100%
Find a file
2026-04-16 14:19:45 +02:00
src Update github links 2026-04-15 11:28:58 +02:00
test Add tests for autocompletion 2025-06-02 17:45:53 +02:00
.gitignore Initial grammar and basic structure 2025-06-02 14:01:04 +02:00
.npmignore Initial grammar and basic structure 2025-06-02 14:01:04 +02:00
CHANGELOG.md Mark version 6.0.1 2026-04-16 14:19:45 +02:00
LICENSE Initial grammar and basic structure 2025-06-02 14:01:04 +02:00
package.json Mark version 6.0.1 2026-04-16 14:19:45 +02:00
README.md Add forwarding link 2026-04-15 12:17:08 +02:00

This repository has moved to https://code.haverbeke.berlin/codemirror/lang-jinja

@codemirror/lang-jinja NPM version

[ WEBSITE | ISSUES | FORUM | CHANGELOG ]

This package implements Jinja template support 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

import {EditorView, basicSetup} from "codemirror"
import {jinja} from "@codemirror/lang-jinja"

const view = new EditorView({
  parent: document.body,
  doc: `{% if a.active %}{{ a.title }}{% endif %}`,
  extensions: [basicSetup, jinja()]
})

API Reference

jinja(config?: JinjaCompletionConfig & Object = {}) → LanguageSupport

Jinja template support.

jinjaLanguage: LRLanguage

A language provider for Jinja templates.

type JinjaCompletionConfig

Configuration options to jinjaCompletionSource.

tags?: readonly Completion[]

Adds additional completions when completing a Jinja tag.

variables?: readonly Completion[]

Add additional global variables.

properties?: fn(path: readonly string[], stateEditorState, contextCompletionContext) → readonly Completion[]

Provides completions for properties completed under the given path. For example, when completing user.address., path will be ["user", "address"].

jinjaCompletionSource(config?: JinjaCompletionConfig = {}) → fn(contextCompletionContext) → CompletionResult | null

Returns a completion source for jinja templates. Optionally takes a configuration that adds additional custom completions.

closePercentBrace: Extension

This extension will, when the user types a % between two matching braces, insert two percent signs instead and put the cursor between them.