Commit f7946429 authored by Christopher C. Wells's avatar Christopher C. Wells
Browse files

Issue #3243437: Implement full plugin with module

parent d5c4f8ad
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
name: CKEditor CodeMirror
type: module
description: Adds the CKEditor CodeMirror source syntax highlighter plugin (http://ckeditor.com/addon/codemirror).
description: Adds syntax highlighting to CKEditor 5 using the CodeMirror library.
package: CKEditor
core_version_requirement: ^9.2 || ^10
dependencies:
+7 −7
Original line number Diff line number Diff line
@@ -18,19 +18,19 @@ function ckeditor_codemirror_requirements($phase): array {
  // If the library is installed.
  $library_path = _ckeditor_codemirror_get_library_path();
  if (file_exists("/$library_path/lib/codemirror.js")) {
    $return['ckeditor_codemirror_library'] = [
      'title' => t('CKEditor CodeMirror'),
    $return['codemirror_library'] = [
      'title' => t('CodeMirror'),
      'severity' => REQUIREMENT_OK,
      'value' => t('CodeMirror version %version installed at %path.',
        [
          '%path' => $library_path,
          '%version' => _ckeditor_codemirror_get_version(),
          '%version' => _ckeditor_codemirror_codemirror_get_version(),
        ]),
    ];
  }
  else {
    $return['ckeditor_codemirror_library'] = [
      'title' => t('CKEditor CodeMirror'),
    $return['codemirror_library'] = [
      'title' => t('CodeMirror'),
      'severity' => REQUIREMENT_ERROR,
      'value' => t('CodeMirror was not found. Download <a href=":link">the latest version of library</a> and place it in the libraries directory (/libraries/codemirror).',
        [':link' => 'https://www.npmjs.com/package/codemirror']
@@ -42,13 +42,13 @@ function ckeditor_codemirror_requirements($phase): array {
}

/**
 * Gets the version information for the ckeditor_codemirror library.
 * Gets the version information for the CodeMirror library.
 *
 * @return string
 *   A string containing the version of the library or empty if the version
 *   cannot be found.
 */
function _ckeditor_codemirror_get_version(): string {
function _ckeditor_codemirror_codemirror_get_version(): string {
  // Provide defaults.
  $options = [
    'file' => 'package.json',
+6 −6
Original line number Diff line number Diff line
@@ -4,9 +4,9 @@ admin:
  dependencies:
    - core/jquery
    - core/drupal
    - core/jquery.once
    - core/drupal.vertical-tabs
    - core/drupalSettings
    - core/once
    - core/drupal.vertical-tabs

codemirror:
  license:
@@ -23,10 +23,10 @@ codemirror:
    component:
      /libraries/codemirror/lib/codemirror.css: {}

code_editor:
source_editing_code_mirror:
  js:
    js/build/codeMirror.js: { preprocess: false, minified: true }
    js/ckeditor5_plugins/ckeditor5-source-editing-codemirror/build/source-editing-codemirror.js: { preprocess: false, minified: true }
  dependencies:
    - ckeditor5/ckeditor5
    - ckeditor5/ckeditor5.sourceEditing
    - core/ckeditor5
    - core/ckeditor5.sourceEditing
    - ckeditor_codemirror/codemirror
+2 −28
Original line number Diff line number Diff line
@@ -5,41 +5,15 @@
 * Main code for CKEditor CodeMirror module.
 */

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function ckeditor_codemirror_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.ckeditor_codemirror':
      $text = file_get_contents(dirname(__FILE__) . '/README.md');
      if (!\Drupal::moduleHandler()->moduleExists('markdown')) {
        return '<pre>' . $text . '</pre>';
      }
      else {
        // Use the Markdown filter to render the README.
        $filter_manager = \Drupal::service('plugin.manager.filter');
        $settings = \Drupal::configFactory()
          ->get('markdown.settings')
          ->getRawData();
        $config = ['settings' => $settings];
        $filter = $filter_manager->createInstance('markdown', $config);
        return $filter->process($text, 'en');
      }
  }
  return NULL;
}

/**
 * Gets the path of a CKEditor CodeMirror library.
 *
 * @return bool|string
 *   The path to the specified library or FALSE if the library wasn't found.
 */
function _ckeditor_codemirror_get_library_path() {
function _ckeditor_codemirror_get_library_path(): bool|string {
  $path = 'libraries/codemirror';
  if (file_exists('libraries/codemirror')) {
  if (file_exists($path)) {
    return DRUPAL_ROOT . "/$path";
  }
  return FALSE;
+1 −1
Original line number Diff line number Diff line
ckeditor5.plugin.ckeditor_codemirror_code_editor:
ckeditor5.plugin.ckeditor_codemirror_source_editing:
  type: config_object
  label: 'CodeMirror Code Editor settings'
  mapping:
Loading