Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@codemirror/lang-python
Advanced tools
@codemirror/lang-python is a language support package for CodeMirror 6 that provides syntax highlighting, code folding, and other language-specific features for Python.
Syntax Highlighting
This code sets up a CodeMirror editor with Python syntax highlighting. The `python` function from `@codemirror/lang-python` is used as an extension in the editor state.
import { python } from '@codemirror/lang-python';
import { EditorState } from '@codemirror/state';
import { EditorView, basicSetup } from '@codemirror/basic-setup';
const state = EditorState.create({
doc: 'print("Hello, World!")',
extensions: [basicSetup, python()]
});
const view = new EditorView({
state,
parent: document.body
});
Code Folding
This code sets up a CodeMirror editor with Python syntax highlighting and code folding. The `foldGutter` extension is used to enable code folding in the editor.
import { python } from '@codemirror/lang-python';
import { foldGutter } from '@codemirror/fold';
import { EditorState } from '@codemirror/state';
import { EditorView, basicSetup } from '@codemirror/basic-setup';
const state = EditorState.create({
doc: 'def foo():\n print("Hello, World!")\n\nfoo()',
extensions: [basicSetup, python(), foldGutter()]
});
const view = new EditorView({
state,
parent: document.body
});
Autocomplete
This code sets up a CodeMirror editor with Python syntax highlighting and autocomplete functionality. The `autocompletion` extension is used to provide autocomplete suggestions.
import { python } from '@codemirror/lang-python';
import { autocompletion } from '@codemirror/autocomplete';
import { EditorState } from '@codemirror/state';
import { EditorView, basicSetup } from '@codemirror/basic-setup';
const state = EditorState.create({
doc: 'pri',
extensions: [basicSetup, python(), autocompletion()]
});
const view = new EditorView({
state,
parent: document.body
});
Monaco Editor is the code editor that powers VS Code. It provides rich language support for Python, including syntax highlighting, code folding, and autocomplete. Compared to @codemirror/lang-python, Monaco Editor offers a more comprehensive set of features and is highly extensible, but it is also larger in size and may be more complex to integrate.
Ace is a standalone code editor written in JavaScript. It provides syntax highlighting, code folding, and autocomplete for Python. Ace is similar to @codemirror/lang-python in terms of functionality but is an older project with a different architecture and API.
Highlight.js is a syntax highlighter written in JavaScript. It supports Python syntax highlighting but does not provide other features like code folding or autocomplete. Highlight.js is simpler and lighter compared to @codemirror/lang-python, making it suitable for use cases where only syntax highlighting is needed.
[ WEBSITE | ISSUES | FORUM | CHANGELOG ]
This package implements Python language 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.
import {EditorView, basicSetup} from "codemirror"
import {python} from "@codemirror/lang-python"
const view = new EditorView({
parent: document.body,
doc: `print("Hello world")`,
extensions: [basicSetup, python()]
})
python() → LanguageSupport
Python language support.
pythonLanguage: LRLanguage
A language provider based on the Lezer Python parser, extended with highlighting and indentation information.
globalCompletion: CompletionSource
Autocompletion for built-in Python globals and keywords.
localCompletionSource(context: CompletionContext) → CompletionResult | null
Completion source that looks up locally defined names in Python code.
6.1.7 (2025-01-18)
Properly indent match/case statements.
FAQs
Python language support for the CodeMirror code editor
The npm package @codemirror/lang-python receives a total of 231,943 weekly downloads. As such, @codemirror/lang-python popularity was classified as popular.
We found that @codemirror/lang-python demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.