欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal wysiwyg ckeditor 回车键是<br /> 不是<p>的设置方法

shiping1 的头像

如果是 纯粹的ckeditor(没有wysiwyg)的话(这肯定是行的)

admin/settings/ckeditor/edit/Advanced

及 admin/settings/ckeditor/edit/Default


 

如果是 ckeditor(有wysiwyg)我找了源代码


sites\all\libraries\ckeditor\ckeditor.js
把里面的大约22行
,enterMode:1,forceEnterMode:false,shiftEnterMode:2,
改成
,enterMode:2,forceEnterMode:false,shiftEnterMode:1,
就好了



 

下面的方法 还是不行 如果是 ckeditor(有wysiwyg)(下面的方法还不行)

是改数据库吧

里面

"shift_enter_mode";s:2:"br"; 及  "enter_mode";s:1:"p";作相应的改动

我的下面的方法是(这种方法不行)

sites\all\modules\ckeditor\ckeditor\_source\core\config.js

约162行

由 enterMode : CKEDITOR.ENTER_P 改成 enterMode : CKEDITOR.ENTER_BR

约193行

由 shiftEnterMode : CKEDITOR.ENTER_BR 改成 CKEDITOR.ENTER_P

 

 

 

 

CKEditor generates <br /> when leaving a textarea field empty

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?

shareimprove this question
  

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.

shareimprove this answer
 
  
+1: thanks, I haven't seen this thread yet. But unfortunately the patch in #49 won't work for me, because I'm using CKEditor module on its own, but this thread (and the comment) is related to WYSIWYG module. :( –  Sk8erPeter Aug 3 '12 at 10:31

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.

shareimprove this answer
 
  
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

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.

shareimprove this answer
 
  
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

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.

shareimprove this answer

来自 http://drupal.stackexchange.com/questions/38856/ckeditor-generates-br-when-leaving-a-textarea-field-...

 

When I'm writing some text with CKeditor and I press enter and want to write something on the next line, the editor automatically inserts the text on the new line into <p> ... </p> tags instead of only <br/>
.

I tried to correct it with editing the config.js file and adding the line config.autoParagraph = false; but without success.

Do you know where is the fault?

shareimprove this question
  

up vote 7 down vote accepted

Out of the box, the CKEditor configuration does a <p> on enter and a <br> on shift + enter.

If you wish to change this, you can visit admin/settings/ckeditor/edit/[profile], and scroll down to the "Cleanup and output" section.

shareimprove this answer
  

Answer above fix this if you have a CKEditor module, but if you use WYSIWYG module you don't have that option (at least for now).

Here is how to override these settings with a module in CKEeditor in Drupal 7:

function YOURMODULENAME_wysiwyg_editor_settings_alter(&$settings, $context) {
  if($context['profile']->editor == 'ckeditor') {
    $settings['enterMode'] = 2; //<br />
    $settings['shiftEnterMode'] = 1; //<p>
  }
}

For TinyMCE here Drupal 7 - How to change p to br in CKEditor and TinyMCE.

shareimprove this answer
  

There is a reason why the paragraph is the default: usually it's semantically more correct to use a <p> tag. I recommend in most cases to stick to the default and (if you don't like the whitespace) remove the margin on paragraphs using CSS.

shareimprove this answer
  

Just go to admin/settings/filters/list; uncheck "Line break" in all filters, and "Full HTML."

来自 http://drupal.stackexchange.com/questions/4013/ckeditor-automatically-making-new-paragraphs

普通分类: