Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CKEditor unwanted   characters

How can I disable CKEditor to get me every time  , when i don't want them? I'm using CKEditor with jQuery adapter.

I don't want to have any   tags.

like image 861
V.Rashkov Avatar asked Mar 16 '12 17:03

V.Rashkov


4 Answers

After some research I might shed some light on this issue - unfortunately there is no out-of-the-box solution.

In the CKEditor there are four ways a no-break space can occur (anybody know more?):

  1. Automatic filling of empty blocks. This can be disabled in the config:

    config.fillEmptyBlocks = false;
    
  2. Automatic insertion when pressing TAB-key. This can be disabled in the config:

    config.tabSpaces = 0;
    
  3. Converting double spaces to SPACE+NBSP. This is a browser behavior and will thus not be fixed by the CKEditor team. It could be fixed serverside or by a clientside javascript onunload. Maybe this php is a start:

    preg_replace('/\s \s/ig', ' ', $text);
    
  4. By copy & paste. If you paste a UTF-8 no-break space or double-spaces CKEditor will convert it automatically. The only solution I see here is doing a regex as above. config.forcePasteAsPlainText = true; doesn't help.

Summary: To get rid of all no-break spaces you need to write an additional function that cleans user input.

Comments and further suggestions are greatly appreciated! (I'm using ckeditor 3.6.4)

like image 100
Tapper Avatar answered Oct 22 '22 00:10

Tapper


There is another way that a non breaking space character can occur. By simply entering a space at the end of a sentence.

CKEditor escapes basic HTML entities along with latin and greek entities.

Add these config options to prevent this (you can also add them in your config file):

CKEDITOR.on( 'instanceCreated', function( event ) {
 editor.on( 'configLoaded', function() {

  editor.config.basicEntities = false;
  editor.config.entities_greek = false; 
  editor.config.entities_latin = false; 
  editor.config.entities_additional = '';

 });
});

These options will prevent CKEditor from escaping nbsp gt lt amp ' " an other latin and greek characters.

Sources: http://docs.ckeditor.com/#!/api/CKEDITOR.config http://docs.ckeditor.com/source/plugin48.html#CKEDITOR-config-cfg-basicEntities

like image 25
gabriel Avatar answered Oct 22 '22 01:10

gabriel


Try:

config.basicEntities = false;

for me fixed the problem.

like image 10
Deyvid. Avatar answered Oct 22 '22 00:10

Deyvid.


in config.js:

CKEDITOR.editorConfig = function( config ) {
  config.enterMode = CKEDITOR.ENTER_BR; // <p></p> to <br />
  config.entities = false;
  config.basicEntities = false;
};

It work for me, after you can print text with php: html_entity_decode( $someText );

like image 4
kampageddon Avatar answered Oct 22 '22 00:10

kampageddon