How to prevent ckeditor to not add   in blank html tag

后端 未结 3 1140
隐瞒了意图╮
隐瞒了意图╮ 2021-02-20 03:21

I have Visual Studio 2012 Express installed in Windows 8.1 OS and using CKEditor in my project as per requirement.

I am new for CKEditor and using it in a proper way as

3条回答
  •  后悔当初
    2021-02-20 03:57

    Have a look at this Post: CKEditor unwanted   characters

    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 knows 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 diabled 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/i', ' ', $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)

    EDIT #1

    Have a look at this.

    CKEDITOR.dtd.$removeEmpty.i= 0;
    

    You can also can use this with span and other tags.

    The documentation to this.

    Stop Removing ANY Empty Tag in CKEditor

    There is a defined list of tags that is going to be removed if empty(see dtd.js and $removeEmpty or run CKEDITOR.dtd.$removeEmpty from console).

    • From HTmL

    To ensure the certain empty tag are not being removed, add attribute ‘data-cke-survive’:

    
    
    • From Configurations

    Or you can configure the particular tag from not be removed:

    if(window.CKEDITOR){
                CKEDITOR.on('instanceCreated', function (ev) {
                    CKEDITOR.dtd.$removeEmpty['span'] = 0;
                    CKEDITOR.dtd.$removeEmpty['TAG-NAME'] = 0;
               }
    }
    

    By setting an element to 0 in the CKEDITOR.dtd.$removeEmpty, it prevents the empty tags from being removed by CKEditor.

    http://margotskapacs.com/

提交回复
热议问题