5

I'm using CKEditor module with satisfaction, but it behaves really frustrating in one case: when leaving textareas empty, it generates <br /> tags in them after rendering CKEditor's interface.

The <code><br /></code> tag in 'Source' view

This can be a problem for example when using "Summary or trimmed" display, and on the node creation form, the Summary field would be left empty, but in fact it's not empty, because it contains a <br /> (so teaser will also contain a single <br />).

I can get round this problem with going to Source view and deleting the <br /> tag all the time, but it's not a solution (other users will not know how to do it).

Do you have any ideas how to stop this behavior?

4

There is an issue tracking this problem on drupal.org - http://drupal.org/node/550428. There is a patch in comment number 49 for it, hope it helps.

2

In sites/all/modules/ckeditor/ckeditor.config.js, add the following line at line 11, just below CKEDITOR.editorConfig = function(config) {:

config.fillEmptyBlocks = false;

You can have a look at CKsource's documentation for more advanced uses of this function. Why config.ignoreEmptyParagraph = true; is not sufficient is beyond my understanding, though.

  • I'm curious is there a way to do that without hacking the source module? Maybe a global JS script that runs after ckeditor.config.js that appends the setting into the config object ? – tenken Aug 30 '12 at 15:20
  • Actually, it's the way the CKeditor module maintainers want you to do it: it's considered a config file. The header says: /* Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ /* WARNING: clear browser's cache after you modify this file. If you don't do this, you may notice that browser is ignoring all your changes. */ – tricasse Aug 31 '12 at 16:29
1

Have you tried setting the fillEmptyBlocks CKEditor setting to false? In WYSIWYG you would do this with a hook:

function base_wysiwyg_extras_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
    $settings['fillEmptyBlocks'] = FALSE;
  }
}

There's probably a CKEditor module way too. If there's not, you can always add settings directly with a custom CKEditor settings js file.

  • OK, thanks for the example in Wysiwyg module, but I would like to know how to do it exactly in the CKEditor module. :) – Sk8erPeter Aug 29 '12 at 12:39
0

Perhaps a hook_field_presave can be used:

function mymodule_field_presave ($entity_type, $entity, $field, $instance, $langcode, &$items)
{
  if ($field[...] == ...) { // update for your case
    foreach ($items as $delta => $item) {
      if (isset($item['value'])) {
        $pattern = '/^\s*\<br\s*\/?\>\s*$/i';
        if (preg_match($pattern, $items[$delta]['value'] === 1) {
          $items[$delta]['value'] = '';
        }
      }
    }
  }
}

This is untested (esp the regex). You may also want to add in additional cases to handle just a &nbsp, just an empty paragraph, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.