I would love to see integration with the WYSIWYG module, especially CKEditor for D7. I know there was a D6 bridge module but it breaks in D7, and I think that maybe it's best to put it into the actual module itself.

CommentFileSizeAuthor
#4 geshifilter-wysiwyg-bridge-1229894-4.patch536 byteswulff

Comments

robloach’s picture

Status: Active » Fixed

I'd suggest hitting up the issue queue over at the bridge about it! http://drupal.org/project/wysiwyg-geshi .

Snugug’s picture

Status: Fixed » Active

That module appears to be abandoned, doesn't have any releasees, and was written for 6.x

robloach’s picture

Most definitely needs some love!

wulff’s picture

StatusFileSize
new536 bytes

I modified the code from the bridge module to work with Wysiwyg and CKEditor in Drupal 7. Currently, the code just lives in a utility module on the site I'm building, but I'll try to find the time to create a proper patch for the bridge module.

My code is in two parts: A hook_wysiwyg_plugin() implementation and a bit of javascript.

The code from the bridge module has been modified a bit. Instead of adding buttons for a few hardcoded filters, it now adds buttons for all enabled GeSHi filters. When you have enabled the GeSHi filters you would like to use, you must edit your WYSIWYG profile to add the new buttons to the editor toolbar.

function utility_wysiwyg_plugin($editor, $version) {
  // based on http://drupal.org/project/wysiwyg-geshi
  if ('ckeditor' == $editor) {
    module_load_include('inc', 'geshifilter');
    $languages = _geshifilter_get_available_languages();

    $buttons = _utility_get_buttons($languages);
    $settings = _utility_get_settings($languages);

    $css = _utility_get_css(array_keys($buttons));

    drupal_add_css($css, 'inline');
    drupal_add_js(array('utilityGeshi' => $settings), 'setting');

    return array(
      'geshi' => array(
        'path' => drupal_get_path('module', 'utility') . '/js',
        'filename' => 'geshi.js',
        'buttons' => $buttons,
        'load' => TRUE,
      ),
    );
  }
}

function _utility_get_buttons($languages) {
  // the generic code button is always available
  $buttons = array(
    'Geshi-code' => 'Geshi: Generic',
  );

  foreach ($languages as $index => $language) {
    if (variable_get('geshifilter_language_enabled_' . $index, FALSE)) {
      $buttons['Geshi-' . $index] = 'Geshi: ' . $language['fullname'];
    }
  }

  return $buttons;
}

function _utility_get_settings($languages) {
  // the setting for the generic code button is always available
  $settings = array(
    'Geshi-code' => array(
      'label' => 'code',
      'settings' => array(
        'element' => 'pre',
      ),
    ),
  );

  foreach ($languages as $index => $language) {
    if (variable_get('geshifilter_language_enabled_' . $index, FALSE)) {
      $settings['Geshi-' . $index] = array(
        'label' => $index,
        'settings' => array(
          'element' => 'pre',
          'attributes' => array(
            'language' => $index,
          ),
        ),
      );
    }
  }

  return $settings;
}

function _utility_get_css($keys) {
  $css = '';

  $icons = $labels = array();
  foreach ($keys as $key) {
    $icons[] = '.cke_skin_kama .cke_button_' . $key . ' span.cke_icon';
    $labels[] = '.cke_skin_kama .cke_button_' . $key . ' span.cke_label';
  }

  $css .= implode(', ', $icons) . '{display: none !important;}';
  $css .= implode(', ', $labels) . '{display: inline;}';

  return $css;
}

The javascript has been cleaned up a bit and now grabs button settings from Drupal.settings.

CKEDITOR.plugins.add('geshi', {
  requires: ['styles', 'button'],

  init: function(editor) {
    // utility function for registering buttons
    var addButtonCommand = function(buttonName, buttonLabel, commandName, styleDefiniton) {
      var style = new CKEDITOR.style(styleDefiniton);

      editor.attachStyleStateChange(style, function(state) {
        editor.getCommand(commandName).setState(state);
      });

      editor.addCommand(commandName, new CKEDITOR.styleCommand(style));

      editor.ui.addButton(buttonName, {
        label: buttonLabel,
        command: commandName
      });
    };

    // add buttons for all active geshi filters
    for (var filter in Drupal.settings.utilityGeshi) {
      addButtonCommand(filter, 'G:' + Drupal.settings.utilityGeshi[filter].label, filter, Drupal.settings.utilityGeshi[filter].settings);
    }
  }
});

If you're using Drush Make, you can use the attached patch to make sure that geshi.php is patched for use with the bridge code.

wulff’s picture

I have added a Drupal 7 patch over at #1351974: Port to D7?.

Snugug’s picture

Cool, thank you much! I'll take a look when I get a chance!

yukare’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Since this patch gone to https://www.drupal.org/project/wysiwyg-geshi i am closing this as i do not anything to geshi here. Please reopen if we need to change something on geshi side of this.