Why CKEditor ignores empty div or is it something else?

时光毁灭记忆、已成空白 提交于 2020-01-06 02:28:13

问题


I have written a plugin that adds bootstrap grid into the editor.However it seems that CKEditor deletes the whole wrapping col div when there is no content inside it.

Plugin on github: https://github.com/radko26/CKEditor_layoutmanagerPlugin/tree/master/layoutmanager

This is what is default inside the dom.When i delete the 'content', the editor removes the wrapping div-layout-column .

<div class="container-fluid layout-container">
  <div class="row  layout-row">
    <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 layout-column">   
        <p>content</p>
     </div>
    <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 layout-column">
       <p>content</p>
    </div>
    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6 layout-column">  
      <p>content</p>   
    </div>
 </div>

I read through this documentation and althought the div element is not stripped on default, i added

 config.protectedSource.push(/<div[^>]><\/div>/g);
 CKEDITOR.dtd.$removeEmpty['div'] = false;

inside the config.js.

http://docs.ckeditor.com/#!/api/CKEDITOR.dtd

I have thought about a workaround: to listen for editor change when layout-column will be with no data,(i must think more about that part), and insert blank space to prevent the editor from removing it, but i was wondering if any event is fired when the editor removes the div or is there easier way to solve my problem.

I tried the solutions suggested but none of them seems to solve the problem.

来源:https://stackoverflow.com/questions/29322028/why-ckeditor-ignores-empty-div-or-is-it-something-else

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!