V.Rashkov
V.Rashkov

Reputation: 1735

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.

Upvotes: 49

Views: 73749

Answers (10)

user3833195
user3833195

Reputation: 21

This is a bad solution

config.basicEntities = false;
  • Because it does not allow you to insert the JS code in the form as text. Like that <script type="text/javascript" src="/scripts/redactor/ckeditor/ckeditor.js"></script>
  • In addition, empty blocks like <p>&nbsp;</p> сan not specify an indent in the text since the character &nbsp; will be deleted (config.fillEmptyBlocks = true;)

This is the right solution

$text = preg_replace("#([^>])&nbsp;#ui", "$1 ", $text);
  • This is a PHP function that replaces all the characters &nbsp; on a space, except those that are inside the tag like <p>&nbsp;</p>
  • The function code is not the most elegant, you can suggest your own version.

Upvotes: 2

Tapper
Tapper

Reputation: 1453

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&nbsp;\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)

Upvotes: 62

pat capozzi
pat capozzi

Reputation: 1459

I had already had to play around with config.js, so in order to fix '?' showing up in safari I ended up with 3 lines in config.js

config.fillEmptyBlocks = function (element) {
return true; // DON'T DO ANYTHING!!!!!};
config.entities = false;
config.basicEntities = false;

Upvotes: 0

kampageddon
kampageddon

Reputation: 1429

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 );

Upvotes: 4

joso
joso

Reputation: 31

I noticed some text editing operations, like deleting a character (by hitting Backspace button) are spliting edited text node into two. Hitting Space Bar at the end of such newly created text node is always resulting into &nbsp; instead of normal space. I am calling normalize() http://www.w3schools.com/jsref/met_node_normalize.asp to changed element after change:

CKEDITOR.on('instanceReady', function (ck) {
    ck.editor.on("change", function (e) {
        var sel = ck.editor.getSelection();
        if (sel) {
            var selected = sel.getStartElement();
            if (selected && selected.$)
                sel.getStartElement().$.normalize();
        }
    });
 });

Upvotes: 3

Deyvid.
Deyvid.

Reputation: 221

Try:

config.basicEntities = false;

for me fixed the problem.

Upvotes: 12

Victor Priceputu
Victor Priceputu

Reputation: 666

I had the same problems creating some tables. What I saw was that if i created the tables with the css rule align="left" the <p>&nbsp;</p> are added, but if i changed the css rule to align="center" i could edit the paragraphs out and they were not added again.

Upvotes: 0

gabriel
gabriel

Reputation: 379

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

Upvotes: 11

xiltepin
xiltepin

Reputation: 80

Add this to your config.js

config.enterMode = CKEDITOR.ENTER_BR,

Upvotes: -3

Maxwell9rk
Maxwell9rk

Reputation: 1

If you're using PHP you can use the following :

preg_replace("/[\<]p[\>][\s]+&nbsp;[\<][\/]p[\>]/" , " " , $pre_comment);

This will remove : "<p> &nbsp;</p>"

Enjoy :)

Maxwell

Upvotes: -3

Related Questions