Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

CodeMirror Field

27 sites Security covered
View on drupal.org

This module integrates the CodeMirror editor as a field type, allowing you to add customizable code snippet fields to entities with syntax highlighting and autocomplete. It supports multiple programming languages and offers extensive configuration options for each field.

CodeMirror Field is a module that integrates the CodeMirror editor as an attachable field. You can find more information about CodeMirror at http://codemirror.net/.

Main features

- It allows you to attach code snippet fields to entities, providing a customizable field widget and formatter.
- You'll also benefit from autocomplete functionality for the supported modes.

Available options

- The widget currently supports four modes: text/html, css, less, and javascript. However, it's easily extendable to other languages supported by CodeMirror.
- Each field instance can have its own unique syntax highlighting theme.
- For more detailed options, please refer to the official CodeMirror documentation at http://codemirror.net/doc/manual.html. You'll find information about options such as indent unit, smart indent, indent with tabs, electric characters, auto clear empty lines, line wrapping, line numbers, gutter, fixed gutter, show cursor when selecting, read only, cursor blink rate, undo depth, auto focus, and drag and drop.

Installation instructions and dependencies for Drupal 7 and Drupal 8+

Drupal 7

Dependencies:

CodeMirror library (https://github.com/marijnh/CodeMirror)
Libraries module (https://www.drupal.org/project/libraries)

Installation

1. Download the CodeMirror library from GitHub and place it in the sites/all/libraries directory. Make sure the library is cloned as codemirror or rename the directory accordingly.
2. Download and enable the Libraries module.
3. Enable the CodeMirror Field module.

Drupal 8+

Installation:

1. Extend your composer.json file with the following code:

"repositories": [{
  "type": "package",
  "package": {
    "name": "codemirror/codemirror5",
    "type": "drupal-library",
    "version": "5",
    "dist": {
      "url": "https://codemirror.net/5/codemirror.zip",
      "type": "zip"
    }
  }
}]

2. Require the library with composer: composer require codemirror/codemirror5
3. Enable the CodeMirror Field module.

Similar Projects

If you're interested in CodeMirror-based editors, you can check out the CodeMirror editor module. It also provides a field widget and a formatter for code snippets.
Another project worth exploring is Wysiwyg CodeMagic, which has a different concept. It works with WYSIWYG and requires TinyMCE.
Feel free to explore these options and find the one that best suits your needs.

Activity

Total releases
1
First release
Apr 2025
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Dormant

Releases

Version Type Release date
2.0.2 Stable Apr 7, 2025