
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@codemirror/lang-cpp
Advanced tools
@codemirror/lang-cpp is a language support package for CodeMirror 6 that provides syntax highlighting, code folding, and other editing features for C++ code.
Syntax Highlighting
This code sets up a CodeMirror editor with C++ syntax highlighting. The `cpp` function from `@codemirror/lang-cpp` is used to enable C++ language support.
import { cpp } from '@codemirror/lang-cpp';
import { EditorState, EditorView, basicSetup } from '@codemirror/basic-setup';
const state = EditorState.create({
doc: 'int main() { return 0; }',
extensions: [basicSetup, cpp()]
});
const view = new EditorView({
state,
parent: document.body
});
Code Folding
This code sets up a CodeMirror editor with C++ syntax highlighting and code folding capabilities. The `foldGutter` and `foldKeymap` extensions are used to enable code folding.
import { cpp } from '@codemirror/lang-cpp';
import { foldGutter, foldKeymap } from '@codemirror/fold';
import { EditorState, EditorView, basicSetup } from '@codemirror/basic-setup';
const state = EditorState.create({
doc: 'int main() {\n // code\n return 0;\n}',
extensions: [basicSetup, cpp(), foldGutter(), foldKeymap]
});
const view = new EditorView({
state,
parent: document.body
});
Autocomplete
This code sets up a CodeMirror editor with C++ syntax highlighting and autocomplete functionality. The `autocompletion` extension is used to provide autocomplete suggestions.
import { cpp } from '@codemirror/lang-cpp';
import { autocompletion } from '@codemirror/autocomplete';
import { EditorState, EditorView, basicSetup } from '@codemirror/basic-setup';
const state = EditorState.create({
doc: 'int main() {\n // code\n return 0;\n}',
extensions: [basicSetup, cpp(), autocompletion()]
});
const view = new EditorView({
state,
parent: document.body
});
Provides similar functionality for JavaScript code, including syntax highlighting, code folding, and autocomplete. It is part of the CodeMirror 6 ecosystem and offers a comparable set of features for JavaScript.
A powerful code editor that provides syntax highlighting, code folding, and autocomplete for multiple languages, including C++. It is developed by Microsoft and used in Visual Studio Code. Compared to @codemirror/lang-cpp, Monaco Editor offers a more comprehensive set of features but is also heavier.
A standalone code editor that supports syntax highlighting, code folding, and autocomplete for various languages, including C++. Ace is lightweight and easy to integrate but may not offer as many advanced features as CodeMirror 6.
[ WEBSITE | ISSUES | FORUM | CHANGELOG ]
This package implements C++ 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.
cpp() → LanguageSupport
Language support for C++.
cppLanguage: LezerLanguage
A language provider based on the Lezer C++ parser, extended with highlighting and indentation information.
6.0.2 (2022-10-24)
Fix (non-)auto indentation in template strings and comments.
Allow prefixed strings to be closed by closeBrackets
.
FAQs
C++ language support for the CodeMirror code editor
The npm package @codemirror/lang-cpp receives a total of 177,550 weekly downloads. As such, @codemirror/lang-cpp popularity was classified as popular.
We found that @codemirror/lang-cpp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.